I have a form running in Access 2003. It has an Exit button with this code
==========================
==========
==========
==========
=
Private Sub btnExit_Click()
'-------------------------
----------
-----
MsgBox "Data uploaded. Thank you!", vbExclamation, "Attention !"
Me.Visible = False
'-------------------------
----------
-----
' loGQuittingFromApplication
is declared in Global module as a boolean.
' loGQuittingFromApplication
set is false at form load
'-------------------------
----------
-----
loGQuittingFromApplication
= True 'means I'm leaving correctly
DoCmd.Quit acQuitSaveAll loGQuittingFromApplication
End Sub
==========================
==========
==========
==========
=
In Form_Unload I look at loGQuittingFromApplication
to see if I'm leaving from the Exit button or the "X", which I want to intercept.
==========================
==========
==========
==========
=
Private Sub Form_Unload(Cancel As Integer)
'Run your "proprer form entry" code here.
Dim vbButtonsToShow As VbMsgBoxStyle
vbButtonsToShow = vbYesNo
If loGQuittingFromApplication
Then
'ok to quit
Else
If MsgBox("Do you really wish to quit ?", vbButtonsToShow, "Confirmation Required !") = vbYes Then
G_UpdateLogInOut strGUserID, "Qt"
Cancel = False
Else
Cancel = True
End If
End If
End Sub
==========================
==========
==========
==========
=
I find that this works fine to intercept the user when they try to leave using the "X" on the title bar of Access, but if this handler is called as a result of the Exit button causing the application to exit I find that the variable loGQuittingFromApplication
has been reset to False. I find the same with a public variable declared within the form (not application-global).
Is there a reason why these variables are being reset ? Is there a "standard" way of communicating the difference between a "DoCmd.Quit " and use of the "X" button to Form_Unload() ?
Start Free Trial