Close Application by Button "X"

Close Access application via the "X" button or your custom button.

With this code, when you close your application using the Exit button or the "X" button, an alert message will be displayed for confirmation.

'Paste the code below into your main form

Private Sub Form_Unload (Cancel As Integer)
If MsgBox ("Do you want to exit the application?", VbYesNo vbQuestion, "Confirmation") = vbYes Then
Application.Quit acQuitSaveAll
Else
Cancel = True 'cancels the Form's Unload event.
End If
End Sub

Private Sub Form_Close ()
DoCmd.Quit
End Sub

'Note:
'If you have an "Exit" button on your form, paste the following code in the event of this button:

Private Sub Cmd_Exit_Click ()
On Error Resume Next
DoCmd.Close
End Sub
Share by: