Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
Discussion GroupsFormsForms ProgrammingQueriesModules / DAO / VBAReports / PrintingMacrosDatabase DesignSecurityConversionImporting / LinkingSQL Server / ADPMultiuser / NetworkingReplicationSetup / ConfigurationDeveloper ToolkitsActiveX ControlsNew UsersGeneral 1General 2
Access DirectoryToolsTutorialsUser Groups
Related Topics
SQL ServerOther DB ProductsMS OfficeMore Topics ...

MS Access Forum / Modules / DAO / VBA / November 2006

Tip: Looking for answers? Try searching our database.

Odd key trapping issue on KeyDown event

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
pubdude2003 - 13 Nov 2006 23:08 GMT
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!
Dirk Goldgar - 14 Nov 2006 02:04 GMT
> 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
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.