Add Interactivity to a Close Application Command Button

Ease of Use


Version tested with

2000, 2003 

Submitted by:



This code allows allows a user to close the application by using a button, providing that they wish to do so. 


This button can be used on any Main Menu Form. When the user clicks on the Quit Application Command Button they will be asked to confirm that they actually want to quit. If they say "yes" the application closes, if they say "no" it resumes normal operation. The code below will not run "as is" and needs to be copied into an existing routine. Instructions have been included below to make this very easy. 


instructions for use


Dim response response = MsgBox("Are You Sure You Want to Quit Access", vbYesNo + vbExclamation + vbDefaultButton2) ' User chose Yes If response = vbNo Then Exit Sub ' User chose No

How to use:

  1. Open the form in Design mode.
  2. Add the command button to your Form by clicking the "Command button" Icon on the Toolbox Menu.
  3. From the Left Pane of theCommand Button Wizard select Application.
  4. In the right Pane click on "Quit Application", then click Next.
  5. Choose the button's Icon and/or click Finish.
  6. Right Click on the newly created Button and choose Properties.
  7. In the the properties window click on the "Event" tab.
  8. Locate "On Click" where it says "Event Procedure" and click just to the right.
  9. Click on the three little dots that show up to the right of the event procedure to bring up the Visual Basic Editor (VBE) with the Code for the button.
  10. Copy the above code.
  11. Paste the code between the "On Error" statement and the "DoCmd" statement.
  12. Exit the VBE, close the Command Button's properties window, and save your changes.

Test the code:

  1. Exit design mode.
  2. Click on the Command Button and select "no", nothing should happen.
  3. Click on the Command Button and select ""yes" and Access will close.

Sample File:

Example 8.94KB 

Approved by mdmackillop

This entry has been viewed 165 times.

Please read our Legal Information and Privacy Policy
Copyright @2004 - 2020 VBA Express