Private Sub form_keydown(KeyCode As Integer, Shift As Integer)
Select Case KeyCode
Case vbKeyF2
'Code here if F2 is pressed
Case Else
End Select
End Sub
That's what I would have thought, but that does nothing for me in either 2000 or 2003 when another control has the focus. In VB you would set the Form.KeyPreview property to True so you can trap keys regardless of what control has the focus. In Access when another control has the focus the Form_KeyDown() procedure will no longer trap for keys. That is, unless I'm missing something.
What do you do, trap for the F2 key in every control on the Form?!?
Create a macro and name it AutoKeys. Then, you can assign key sequences to be trapped. For your case, {F2} would trap F2 function key. ^{F2} would require CTRL + F2. You can google to get a list of all shortcut keys.
This sounds like what you are referring to.... I use this to change to "Caps" on the tab key and do nothing on the "Enter" key.
Private Sub Form_Load()
Me.KeyPreview = True
End Sub
Private Sub Form_KeyDown(KeyCode As Integer, Shift As Integer)
If KeyCode = vbKeyTab And Screen.ActiveControl.Tag = "Cap" Then
Screen.ActiveControl.Text = StrConv(Screen.ActiveControl.Text, 3)
End If
End Sub