Trap For Function Keys (1 Viewer)

GrexP

Thanks, Grex
Local time
Today, 13:39
Joined
Aug 1, 2007
Messages
51
I want to know when the user pushes key F2. I can do it in VB but I can't figure out how to do it in Access VBA.
 

missinglinq

AWF VIP
Local time
Today, 16:39
Joined
Jun 20, 2003
Messages
6,423
Code:
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
Linq ;0)>
 

GrexP

Thanks, Grex
Local time
Today, 13:39
Joined
Aug 1, 2007
Messages
51
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?!?
 

MarkK

bit cruncher
Local time
Today, 13:39
Joined
Mar 17, 2004
Messages
8,180
Access Forms also have a KeyPreview property. It's just below the "On Key ..." propeties on the Event tab.
 

shudini

Registered User.
Local time
Today, 16:39
Joined
Mar 1, 2007
Messages
114
You could always use an AutoKeys macro.

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.
 

CEH

Curtis
Local time
Today, 15:39
Joined
Oct 22, 2004
Messages
1,187
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
 

GrexP

Thanks, Grex
Local time
Today, 13:39
Joined
Aug 1, 2007
Messages
51
Access Forms also have a KeyPreview property. It's just below the "On Key ..." propeties on the Event tab.

Crap! It is there. I think maybe I had just been staring at the screen too long.

Thanks :rolleyes:
 

missinglinq

AWF VIP
Local time
Today, 16:39
Joined
Jun 20, 2003
Messages
6,423
Sorry I forgot to include that; I always have it set to YES and it slipped this feable mind!
 

Users who are viewing this thread

Top Bottom