Notice: This website is an unofficial Microsoft Knowledge Base (hereinafter KB) archive and is intended to provide a reliable access to deleted content from Microsoft KB. All KB articles are owned by Microsoft Corporation. Read full disclaimer for more details.

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


View products that this article applies to.

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).

↑ Back to the top


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.

↑ Back to the top


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.

↑ Back to the top


Keywords: KB210601, kbhowto

↑ Back to the top

Article Info
Article ID : 210601
Revision : 4
Created on : 10/11/2006
Published on : 10/11/2006
Exists online : False
Views : 378