Capturing Enter key press inconsistent behaviour



I have a form with various text boxes and buttons.

One button is the Default, so any "Enter" key presses trigger that
button's Click event.

I added a new text box and a new button. For this text box, when the
user presses Enter, the NEW button's click event must be triggered.

I trap the Enter key in the KeyDown event of the new text box, looking
for a keycode of 13.

Here's the problem:
- If i put a breakpoint in the code, the Enter key is trapped and the
correct button's click event is called
- if i tab into the new text box from another text box and immediately
press enter, it works correctly.
- if i TYPE something in the new text box and THEN press enter, the
default action is triggered, and my Enter key handling doesn't work.

Any ideas?

(running Access 2003)



Albert D.Kallal

You likely are not throwing out the keypress.....

Access is being confused, since you have Enter key = default for a
particular button....

In anther want to do something else...

Add the following line of code

keypress = 0 ' throw keypress into black hole...access will not see

Hence,your you code would (something) like

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

If KeyCode = 13 Then

KeyCode = 0 ' black hold for key...

Call Command30_Click
End If

End Sub

By adding the keycode = 13, then the standard default button, or anything
else for that matter will NOT see/get/use the keypress....

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