The sample database Northwind.mdb contains the Main Switchboard form with several buttons, one of which is the
Exit Microsoft Access button. When you click this button, it causes Microsoft Access to quit completely. Sometimes, you may want to just close the Main Switchboard form and keep Microsoft Access and the database open.
Instead of creating one command button to quit Microsoft Access and
another button to close the Main Switchboard form, the following example shows you how to create one button that is capable of doing both,
depending on whether you click the button or press and hold CTRL, and then click the button.
CAUTION: If you follow the steps in this example, you modify the sample database Northwind.mdb. You may want to back up the Northwind.mdb file and follow these steps on a copy of the database.
- Start Microsoft Access and open the sample database Northwind.mdb.
- Open the Main Switchboard form in Design view.
- Add the following event procedure to the OnMouseDown property of the Exit Microsoft Access command button:
Private Sub ExitMicrosoftAccess_MouseDown(Button As Integer, Shift _
As Integer, X As Single, Y As Single)
If Shift And acCtrlMask Then
DoCmd.Close
End If
End Sub
Other intrinsic constants available for Microsoft Access 2000 are acShiftMask and acAltMask, representing the SHIFT and ALT keys respectively.
- Save the form and open it in Form view.
- Click Exit Microsoft Access. Note that Microsoft Access quits.
- Restart Microsoft Access, and then open the Main Switchboard form in Form view.
- Press and hold down CTRL, and then click the Exit Microsoft Access button. Note that only the Main Switchboard form closes.