Solved

Trigger code in MS Access 2007 if two keys are pressed simultaneously

Posted on 2009-07-14
3
296 Views
Last Modified: 2013-11-27
I would like to trigger some admin options to run in VBA when a combination of keys are pressed at the same time.  How can I code the condition for two keys simultaneously pressed?
0
Comment
Question by:marku24
  • 2
3 Comments
 
LVL 39

Expert Comment

by:thenelson
ID: 24855369
If the combination is some key with control, shift or alt then key down or key up will handle this nicely. The KeyCode argument will contain the key, the Shift argument will contain the control, shift and alt combinations.

If you want to capture two key codes like "a" and "i" together, then you would need to capture the keyboard interrupt directly which I don't think is possible with VBA.
0
 

Author Comment

by:marku24
ID: 24855417
Thanks , really helpful.  Woudl you have an example of how to use KeyCode with Shift or Alt?  I googled but am having a problem getting it to work.
0
 
LVL 39

Accepted Solution

by:
thenelson earned 250 total points
ID: 24855562
Here is an example in VBA help for the Key Down event:

Private Sub KeyHandler_KeyDown(KeyCode As Integer, _
     Shift As Integer)
    Dim intShiftDown As Integer, intAltDown As Integer
    Dim intCtrlDown As Integer

    ' Use bit masks to determine which key was pressed.
    intShiftDown = (Shift And acShiftMask) > 0
    intAltDown = (Shift And acAltMask) > 0
    intCtrlDown = (Shift And acCtrlMask) > 0
    ' Display message telling user which key was pressed.
    If intShiftDown Then MsgBox "You pressed the SHIFT key."
    If intAltDown Then MsgBox "You pressed the ALT key."
    If intCtrlDown Then MsgBox "You pressed the CTRL key."
End Sub

Private Sub object_KeyDown(KeyCode As Integer, Shift As Integer)
Object    The name of a Form or control on a Form.

KeyCode    A key code, such as vbKeyF1 (the F1 key) or vbKeyHome (the HOME key). To specify key codes, use the intrinsic constants shown in the Object Browser. You can prevent an object from receiving a keystroke by setting KeyCode to 0.

Shift    The state of the SHIFT, CTRL, and ALT keys at the time of the event. If you need to test for the Shift argument, you can use one of the following intrinsic constants as bit masks:

Constant Description

acShiftMask The bit mask for the SHIFT key.

acCtrlMask The bit mask for the CTRL key.

acAltMask The bit mask for the ALT key.

0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

This article is a continuation or rather an extension from Cascading Combos (http://www.experts-exchange.com/A_5949.html) and builds on examples developed in detail there. It should be understandable alone, but I recommend reading the previous artic…
Experts-Exchange is a great place to come for help with solutions for your database issues, and many problems are resolved within minutes of being posted.  Others take a little more time and effort and often providing a sample database is very helpf…
Learn how to number pages in an Access report over each group. Activate two pass printing by referencing the pages property: Add code to the Page Footers OnFormat event to capture the pages as there occur for each group. Use the pages property to …
In Microsoft Access, learn different ways of passing a string value within a string argument. Also learn what a “Type Mis-match” error is about.

708 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now