|
|
|
|
|
|
Access
|
Add Interactivity to a Close Application Command Button
|
|
Ease of Use
|
Easy
|
Version tested with
|
2000, 2003
|
Submitted by:
|
OBP
|
Description:
|
This code allows allows a user to close the application by using a button, providing that they wish to do so.
|
Discussion:
|
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.
|
Code:
|
instructions for use
|
Dim response
response = MsgBox("Are You Sure You Want to Quit Access", vbYesNo + vbExclamation + vbDefaultButton2)
If response = vbNo Then Exit Sub
|
How to use:
|
- Open the form in Design mode.
- Add the command button to your Form by clicking the "Command button" Icon on the Toolbox Menu.
- From the Left Pane of theCommand Button Wizard select Application.
- In the right Pane click on "Quit Application", then click Next.
- Choose the button's Icon and/or click Finish.
- Right Click on the newly created Button and choose Properties.
- In the the properties window click on the "Event" tab.
- Locate "On Click" where it says "Event Procedure" and click just to the right.
- 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.
- Copy the above code.
- Paste the code between the "On Error" statement and the "DoCmd" statement.
- Exit the VBE, close the Command Button's properties window, and save your changes.
|
Test the code:
|
- Exit design mode.
- Click on the Command Button and select "no", nothing should happen.
- Click on the Command Button and select ""yes" and Access will close.
|
Sample File:
|
Example database.zip 8.94KB
|
Approved by mdmackillop
|
This entry has been viewed 165 times.
|
|