Microsoft KB Archive/209984

= ACC2000: How to Set a Keystroke + Click to Activate a Command Button =

Article ID: 209984

Article Last Modified on 7/15/2004

-

APPLIES TO


 * Microsoft Access 2000 Standard Edition

-



This article was previously published under Q209984



Moderate: Requires basic macro, coding, and interoperability skills.

This article applies to a Microsoft Access database (.mdb) and to a Microsoft Access project (.adp).



SUMMARY
This article describes a method for using a keystroke + click combination with a command button. For example, you may want click, ALT + click, and CTRL + click to have different actions on the same command button.



MORE INFORMATION
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.</li> Press and hold down CTRL, and then click the Exit Microsoft Access button. Note that only the Main Switchboard form closes.</li></ol>

<div class="references_section">