Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

KEYDOWN sequence of keys

Status
Not open for further replies.

DH

Programmer
Dec 8, 2000
168
How can I code a form to open another form when a sequence of keys are pushed on a keyboard?

For example, I would like to push and hold down the following keys "Ctrl" and "D" and "L" to open a form.

The form that will be opened is a special database maintenance screen that only a limited number of users will know about.

Any suggestions on how the code should look?

Thanks!

 
What you need is basically this:
Code:
Private Sub Form_KeyDown(KeyCode As Integer, Shift As Integer)
    Static fCtrlDPressed As Boolean
    
    If (KeyCode = vbKeyD) And (Shift And acCtrlMask) Then
        fCtrlDPressed = True
        KeyCode = 0
    Else
        If fCtrlDPressed And KeyCode = vbKeyL Then
            DoCmd.OpenForm...
            KeyCode = 0
        End If
        fCtrlDPressed = False
    End If
End Sub
However, the Form normally only receives a KeyDown event when no control is focused, or when the focused control has no KeyDown event. If the focused control does have a KeyDown event, it will handle the event, even if you have written no event procedure.

To make sure the Form always has first crack at a KeyDown, set the KeyPreview property to Yes.

As an alternative, you could tell your special users that they have to click in a particular text box before hitting Ctrl-D L, and put the above code in that text box's event procedure instead. Rick Sprague
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top