Using "SendKeys" is supposed to work, but I've had mixed success with it, and going by many postings I've read here and elsewhere, many others also have problems with it. A method I've used very successfully, however, allows you to assign any function you want to any special key, i.e. <Esc>, <Up Arrow>, <Down Arrow>, etc. You need to enter the following two subs in code:
Private Sub Form_Load()
Me.KeyPreview = True
End Sub
This sub makes Access look at the special keys when they are pressed.
Then enter:
Private Sub Form_KeyDown(KeyCode As Integer, Shift As Integer)
Select Case KeyCode
Case vbKeyEscape
' Process Escape Key events.
Case vbKeyUp
' Process Up Arrow Key events.
Case vbKeyDown
' Process Down Arrow Key events.
Case vbKeyF2
' Process F2 key events.
Case vbKeyF3
' Process F3 key events.
Case vbKeyF4
' Process F4 key events.
Case Else
End Select
End Sub
Under each "Case" enter the code you want executed when the particular key is pressed.
Hope this is helpful.
The Missinglinq
"It's got to be the going,
not the getting there that's good!"
-Harry Chapin
Hi mybers,
You can determine whether the SHIFT, CTRL or ALT keys have been pressed in combination with any other key by using the Shift argument. If the Shift Key was pressed then the value passed is 1. If CTRL it is 2, if ALT it is 4. Any other key passes the value of 0.
Access also has the constants acShiftMask, acCtrlMask and acAltMask which you can use as well.
Hope that helps.
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.