I prepared this bit of code over a year ago and it works fine on my computer.
However I have recently been trying to trap a "~" (tilde) symbol to do a
quick form open and can't seem to get it to work.
Question one is how do I trap the "~" key?
And question two is can anyone explain why this is working? I don't appear to
be trapping the correct keycodes... but I must be, it's working fine on my
machine, Access 2003 in XP
Case 111, 191 'Divide
KeyCode = 0
SendKeys "{tab}"
SendKeys "/"
Case 106 'Multiply
KeyCode = 0
SendKeys "{tab}"
SendKeys "*"
Case 107 'Addition
KeyCode = 0
SendKeys "{tab}"
SendKeys "{+}"
Case 109, 189 'Minus
KeyCode = 0
SendKeys "{tab}"
SendKeys "{-}"
Any help would be appreciated!
> I prepared this bit of code over a year ago and it works fine on my
> computer. However I have recently been trying to trap a "~" (tilde)
[quoted text clipped - 23 lines]
>
> Any help would be appreciated!
The key codes are right, though incomplete -- you're missing the shifted
alternatives for addition and multiplication (from the top row of the
main set of keys). The tilde is also a shifted key. To check for the
shifted keys using the KeyDown event (which gives you keyboard scan
codes, not ASCII codes), you have to check the Shift argument that is
passed to the event procedure, to see if the Shift key was also pressed:
Case 192
If (Shift And acShiftMask) > 0 Then
KeyCode = 0
DoCmd.OpenForm ...
End If
If these are all the keys you're checking for, it might be easier to use
the KeyPress event instead of KeyDown. The KeyPress event passes the
ASCII character value, so you don't need to worry about whether the
Shift key was down or not, and you don't have to allow for alternate key
codes that translate to the same character. Of course, you'd have to
change the set of codes you check for, as the ASCII character codes
aren't the same as the key codes.

Signature
Dirk Goldgar, MS Access MVP
www.datagnostics.com
(please reply to the newsgroup)
pubdude2003 - 14 Nov 2006 02:23 GMT
Thanks very much Dirk, I suspected I wasn't using ascii code but it had been
so long, I couldn't remember my thinking at the time.
Can you direct me to a chart of the keyboard scan codes? Because of the
nature of the form I would prefer them to use the keypad rather thank the
keyboard and would rather not recode the forms involved.
Dirk Goldgar - 14 Nov 2006 02:38 GMT
> Thanks very much Dirk, I suspected I wasn't using ascii code but it
> had been so long, I couldn't remember my thinking at the time.
>
> Can you direct me to a chart of the keyboard scan codes? Because of
> the nature of the form I would prefer them to use the keypad rather
> thank the keyboard and would rather not recode the forms involved.
In the VB Editor, type "KeyCode Constants" in the "search help" box, or
navigate to it via the (VBA) help contents pane: "Constants/KeyCode
Constants"

Signature
Dirk Goldgar, MS Access MVP
www.datagnostics.com
(please reply to the newsgroup)
pubdude2003 - 14 Nov 2006 03:11 GMT
of course... silly me, thanks again for the help Dirk, appreciate your
responses