Hitting Enter Key Triggers Field OnClick Event

J

JamesJ

I have a sub form with only one field enabled. There's an On Click
event on this enabled field that opens another form. When I click or right
click
on the form this field becomes 'selected'. If I then press the enter key the
code for the On Click triggers and the form opens.
How can I prevent this???
I've trapped the enter key in the On Key Down using:

If KeyCode = vbKeyReturn Then

End If

Didn't work though.

Any help will be appreciated,
James
 
S

Stuart McCall

JamesJ said:
I have a sub form with only one field enabled. There's an On Click
event on this enabled field that opens another form. When I click or right
click
on the form this field becomes 'selected'. If I then press the enter key
the
code for the On Click triggers and the form opens.
How can I prevent this???
I've trapped the enter key in the On Key Down using:

If KeyCode = vbKeyReturn Then

End If

Didn't work though.

Any help will be appreciated,
James

You missed one line:

If KeyCode = vbKeyReturn Then
KeyCode = 0 'This "throws away" the keypress
End If
 

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