Pacific Database

Home | Contact | FAQs | View Cart

A world of information at your fingertips

Access-specific :: Shutdown Access

Shutdown the Access application using VBA

To shutdown the Access application, you can use Application.Quit.

The Quit method takes one optional parameter, which can be one of the following three AcQuitOption constants:

  • acQuitSaveNone - Quits Access without saving any objects.
  • acQuitSaveAll - Saves all objects without displaying a dialog box. This is the default action.
  • acQuitPrompt - Displays a dialog box that asks whether you want to save any database objects that have been changed but not saved.

Application.Quit acQuitSaveNone

Shutdown the Access application using the Windows API

The following function, created by Albert Kallal MVP, allows you to cleanly shutdown the Access application. Of course you could do it with Application.Quit, but sometimes the Access application fails to shutdown if one ore more objects remain instantiated. Therefore, this is a better approach.

Click here to read a commentary by Albert on shutting down Access is this way.

Declare Function PostMessage Lib "user32" Alias "PostMessageA" _
    (ByVal hwnd As Long, _
    ByVal wMsg As Long, _
    ByVal wParam As Long, _
    ByVal lParam As Long) As Long
Const WM_CLOSE = &H10
'If the function succeeds, the return value is nonzero
Public Function ExitDatabase() As Long
    ExitDatabase = PostMessage(Application.hWndAccessApp, WM_CLOSE, &H0, &H0)
End Function