How do I detect a keystroke

  • Thread starter Thread starter Mike
  • Start date Start date
M

Mike

How do I detect a keystroke within a vb sub in a access database? I build a
search engine into my telephone number book application.Activates a filter.
Right now you use a mouse to navigate this form. My wife says it faster if
you can keep your hands on the key board to navigate. That is why I need to
find a way to detect keystroke events with in my program.Any help would be
appreciated. If you could point me to a good code reference book that would
be greater.
 
Mike, your wife is quite right ('I hate meeces, to pieces!' - who was it who
said that?)

Check out the OnGotFocus and Enter events in the VBEditor against the
appropriate control from your form.
(Select the Control name from the left-hand combo box above the code pane,
and then the Event name from the right-hand combo box)

Unlike Excel, I don't think Access has an Onkey method.
 
Mike said:
How do I detect a keystroke within a vb sub in a access database? I build a
search engine into my telephone number book application.Activates a filter.
Right now you use a mouse to navigate this form. My wife says it faster if
you can keep your hands on the key board to navigate. That is why I need to
find a way to detect keystroke events with in my program.Any help would be
appreciated. If you could point me to a good code reference book that would
be greater.

The help file is a good reference. Some of the methods to look at follow.

Many controls have KeyDown, KeyUp and KeyPress events. KeyDown and
KeyUp give you access to the keycode of the key that is being used. There
are defined keycode constants for most(all?) keycodes such as vbKeyBack,
vbKeyDown, vbKeyLeft, vbKeyA thru vbKeyZ that are fairly intuitive.

There is also the KeyPreview property of the Form object that allows you
to intercept and handle key events before they are handled by the control
events. Open a form's property sheet. Look for Key Preview under the
Events tab. Put the cursor in the corresponding combobox and hit F1 to
read all about it.

There are also a few options that can be set under the Keyboard tab of the
Tools, Options menu item.
 
Mike said:
How do I detect a keystroke within a vb sub in a access database? I build a
search engine into my telephone number book application.Activates a filter.
Right now you use a mouse to navigate this form. My wife says it faster if
you can keep your hands on the key board to navigate. That is why I need to
find a way to detect keystroke events with in my program.

Why not just use the AfterUpdate event when the user tabs out of the
field?

Tony
--
Tony Toews, Microsoft Access MVP
Please respond only in the newsgroups so that others can
read the entire thread of messages.
Microsoft Access Links, Hints, Tips & Accounting Systems at
http://www.granite.ab.ca/accsmstr.htm
 
Back
Top