Solved

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

Posted on 2009-07-14
3
307 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

Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction When developing Access applications, often we need to know whether an object exists.  This article presents a quick and reliable routine to determine if an object exists without that object being opened. If you wanted to inspect/ite…
As tax season makes its return, so does the increase in cyber crime and tax refund phishing that comes with it
Familiarize people with the process of utilizing SQL Server functions from within Microsoft Access. Microsoft Access is a very powerful client/server development tool. One of the SQL Server objects that you can interact with from within Microsoft Ac…
In Microsoft Access, learn the trick to repeating sub-report headings at the top of each page. The problem with sub-reports and headings: Add a dummy group to the sub report using the expression =1: Set the “Repeat Section” property of the dummy…

813 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

14 Experts available now in Live!

Get 1:1 Help Now