
Access 97 - Application.Quit does not work if msgbox is displayed
The only way to close a modal dialog would be to run code using a form's
Timer event. Also be careful about what type of MsgBox's can be displayed
from your app. You may not want to close a critical confirmation MsgBox by
force, for example.
Private Sub Command0_Click()
MsgBox Now
End Sub
Private Sub Form_Timer()
Debug.Print fCloseMsgBox
End Sub
'******** Code Start *********
Private Declare Function apiFindWindow Lib "user32" _
Alias "FindWindowA" _
(ByVal lpClassName As String, _
ByVal lpWindowName As String) _
As Long
Private Declare Function apiGetLastActivePopup Lib "user32" _
Alias "GetLastActivePopup" _
(ByVal hWndOwnder As Long) _
As Long
Private Declare Function apiPostMessage Lib "user32" _
Alias "PostMessageA" _
(ByVal hWnd As Long, _
ByVal wMsg As Long, _
ByVal wParam As Long, _
ByVal lParam As Long) _
As Long
Private Const MSGBOX_CLASS = "#32770"
Private Const WM_CLOSE = &H10
Function fCloseMsgBox() As Boolean
Dim hWnd As Long
hWnd = apiFindWindow(MSGBOX_CLASS, vbNullString)
If hWnd = apiGetLastActivePopup(hWndAccessApp) Then
fCloseMsgBox = Not (apiPostMessage(hWnd, WM_CLOSE, 0, 0) = 0)
End If
End Function
'********* Code End *******
-- Dev
: I am using the form timer event to close an application at a specific
time.
: This works great if there are no system message boxes displayed. If a
: msgbox is displayed when the Application.quit code executes, the app does
: not close.
:
: Is there a method or command to quit the application no matter what,
: everytime?
:
: I am trying to force users out at night so I can compact the backend
: database.
:
:
:
: