ACC2000: How to Use Visual Basic for Applications Code in Microsoft Access to Quit Windows (210601)



The information in this article applies to:

  • Microsoft Access 2000

This article was previously published under Q210601
Advanced: Requires expert coding, interoperability, and multiuser skills.

This article applies to a Microsoft Access database (.mdb) and to a Microsoft Access project (.adp).

SUMMARY

It is possible to quit Microsoft Windows from within a Microsoft Access application by using a Windows application programming interface (API) function. To do this, you must create a module that declares the API function and a procedure to call the API function.

MORE INFORMATION

The call to the Windows dynamic-link library (DLL) below behaves in the same way as the Shut Down command on the Start menu in Microsoft Windows 95, Microsoft Windows 98, Microsoft Windows Millennium Edition (Me), Microsoft Windows NT 4.0, and Microsoft Windows 2000. Each program must agree to be closed; for example, if you click Cancel when you are prompted to save a file, your quit request is also canceled.

To create a Microsoft Access function that quits Windows, follow these steps:
  1. Create a module, and then type the following code in the Declarations section:
    Declare Function ExitWindowsEx Lib "user32" (ByVal uFlags As _
    Long, ByVal dwReserved As Long) As Long
    					
  2. Add the following procedure:
    Function ShutDownWindows()
       'This will quit all applications and shut down Windows.
       Dim x As Long
       x = ExitWindowsEx(1, 0)
       application.Quit acExit
    End Function
    					
    NOTE: If you are using Microsoft Windows NT or Windows 2000, or if you would like to quit all applications but not log off the user, you can change the first ExitWindowsEx argument to 0, as follows:
    x = ExitWindowsEx(0, 0)
    					
  3. Save the module as WinExit, and then close it.
You can now add the code to a form and use it as you would any other Microsoft Access procedure.

NOTE: Microsoft does not recommend quitting Microsoft Access by using Windows API calls, although quitting in this manner can be safely accomplished. In some cases, temporary files can be left in the Windows Temp folder; however, you can safely delete the Temp files.

Modification Type:MinorLast Reviewed:10/11/2006
Keywords:kbhowto KB210601