Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Exit Access Application

Access Environment

Exit Access Application

by  rohalyla  Posted    (Edited  )
Couldn't find code anywhere to close/exit access - so thought I'd post it. I think you can use the button wizard to create a button to do this too, but I usually don't use the wizards and go straight to event code. This is something I've used many times in my databases - surprised it wasn't a FAQ already.

This code is behind a button click event. It closes the form and then exits access. Note - I use this for an Exit button on the Main Menu or Switchboard screen. If you use this code somewhere else, I would add code to close any open database objects, before exiting access, to prevent database corruption. Not that it would, but you never know with Access...

Create form and add button called cmdExitDatabase. Add this code to the on click event for the button.
Code:
Private Sub cmdExitDatabase_Click()
On Error GoTo Err_cmdExitDatabase_Click
    
    ' First close the form
    DoCmd.Close

    ' Exit database and quit access
    DoCmd.Quit

Exit_cmdExitDatabase_Click:
    Exit Sub

Err_cmdExitDatabase_Click:
    MsgBox Error$
    Resume Exit_cmdExitDatabase_Click
    
End Sub
Register to rate this FAQ  : BAD 1 2 3 4 5 6 7 8 9 10 GOOD
Please Note: 1 is Bad, 10 is Good :-)

Part and Inventory Search

Back
Top