Notice: This website is an unofficial Microsoft Knowledge Base (hereinafter KB) archive and is intended to provide a reliable access to deleted content from Microsoft KB. All KB articles are owned by Microsoft Corporation. Read full disclaimer for more details.

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


View products that this article applies to.

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).

↑ Back to the top


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.

↑ Back to the top


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.

  1. Start Microsoft Access and open the sample database Northwind.mdb.
  2. Open the Main Switchboard form in Design view.
  3. 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.

  4. Save the form and open it in Form view.
  5. Click Exit Microsoft Access. Note that Microsoft Access quits.
  6. Restart Microsoft Access, and then open the Main Switchboard form in Form view.
  7. Press and hold down CTRL, and then click the Exit Microsoft Access button. Note that only the Main Switchboard form closes.

↑ Back to the top


References

For more information about mouse events, in the Visual Basic Editor, click Microsoft Visual Basic Help on the Help menu, type mouse events in the Office Assistant or the Answer Wizard, and then click Search to view the topic.

For more information about constants applicable to mouse events, in the Visual Basic Editor, click Microsoft Visual Basic Help on the Help menu, type intrinsic constants as bit masks in the Office Assistant or the Answer Wizard, and then click Search to view the topic.

↑ Back to the top


Keywords: KB209984, kbprogramming, kbinfo, kbhowto

↑ Back to the top

Article Info
Article ID : 209984
Revision : 4
Created on : 7/15/2004
Published on : 7/15/2004
Exists online : False
Views : 392