Processing Key strokes

G

Guest

I am to capture the Enter or the Tab key to execute a special set of
instructions. What I want to do is process all other key strokes normally;
so that if the a is pressed then an "a" appears on the screen. Is there a
function or process that allows me to get the keystrokes that are not Enter
or Tab to behave the way they always do?
 
A

Albert D. Kallal

yes, you use the keydown event of the FORM....not the controls event code.

You must also set the forms keypreview = yes.

The following code snip for example makes the arrow keys work the same in a
continues form as they do in a datasheet

eg: up/down arrow keys move the cursor up/down.

Note how the code below KILLS THE KEYSTOKE with

keycode = 0

The above keycode flushes the keystork into a black hole, and ms-access DOES
NOT get a change to use, or react to the keystoocke.

Private Sub Form_KeyDown(KeyCode As Integer, Shift As Integer)

' key hand

Select Case KeyCode

Case vbKeyEscape
KeyCode = 0
DoCmd.Close

Case vbKeyUp
KeyCode = 0
On Error Resume Next
DoCmd.GoToRecord acActiveDataObject, , acPrevious

Case vbKeyDown
KeyCode = 0
On Error Resume Next
DoCmd.GoToRecord acActiveDataObject, , acNext

Case vbKeyReturn
If IsNull(Me.ID) = False Then
KeyCode = 0
Call EditMain
End If

End Select

End Sub


I also have the enter key re-mapped in this form..and if the user hits
enter..I launch another form in the code routine edit main....
 
G

Guest

I really need to have this handled on the control level; because I have two
controls that will need to execute code when the Enter or Tab key is pressed.
Is that possible I could do this if I was developing this in VB.Net instead
of Access.
 
A

Albert D. Kallal

JC1269 said:
I really need to have this handled on the control level; because I have two
controls that will need to execute code when the Enter or Tab key is
pressed.


Sure...you made no mention of needing this for a particular control..and I
had to "guess" that you wanted to do this for the WHOLE form...


Sure...no problem..just use the individual controls keydown event (all
controls have this ability..so, you CAN code for a single control).

The same suggestion to use keycode = 0 to disable the key, and let YOUR
code do what you want also applies to the keydown event for a given control.

So, sure..I see no problem with keystroke processing for a given control...

So, you can have a keydown event for the WHOLE form, and this form will
PROCESS the keystrokes BEFORE your code for the individual control will
*ever* get/see the keystroke.

In your case, this advice don't matter, since you are not using forms level
key processing, but at least you can now see that code could still be run at
the forms level BEFORE the control level. Ms-access gives you good
flexibility in this regards.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top