Solved

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

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

Migrating Your Company's PCs

To keep pace with competitors, businesses must keep employees productive, and that means providing them with the latest technology. This document provides the tips and tricks you need to help you migrate an outdated PC fleet to new desktops, laptops, and tablets.

Question has a verified solution.

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

I see at least one EE question a week that pertains to using temporary tables in MS Access.  But surprisingly, I was unable to find a single article devoted solely to this topic. I don’t intend to describe all of the uses of temporary tables in t…
It’s the first day of March, the weather is starting to warm up and the excitement of the upcoming St. Patrick’s Day holiday can be felt throughout the world.
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.
With Microsoft Access, learn how to start a database in different ways and produce different start-up actions allowing you to use a single database to perform multiple tasks. Specify a start-up form through options: Specify an Autoexec macro: Us…

840 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