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