Lost Focus/Enter Key Hit ?

  • Thread starter Thread starter Dave Ruhl
  • Start date Start date
D

Dave Ruhl

Hello, I want to know how I can tell if the ENTER key was
hit to make a control lose focus (as opposed to TAB or a
mouse click). I've tried the OnKeyPress event, but it
doesn't get triggered by the ENTER key. I've also tried
the OnKeyDown event. It does catch the ENTER key, but
leaves my textbox with a NULL value, even if data appears
to be in it. Can this be done ? Thanks!
 
Hi Dave,

Anytime you have questions about your code it's a good idea to post the
relevant bits of code so we can help you spot your problems. I suspect
you've got something wrong but I have no idea what - this code works:

Private Sub Text4_KeyDown(KeyCode As Integer, Shift As Integer)
If KeyCode = vbKeyReturn Then
MsgBox "Enter"
ElseIf KeyCode = vbKeyTab Then
MsgBox "Tab"
End If
End sub

Feel free to post back with your code if you still need help.
 
Hi Sandra, thanks for the response. Actually my test for
the OnKeyDown event looked just like yours, and yes it
does work. However, it leaves a NULL value in my textbox
field. The OnKeyPress event leaves my data as-is, but
doesn't catch the ENTER key.
-----Original Message-----
Hi Dave,

Anytime you have questions about your code it's a good idea to post the
relevant bits of code so we can help you spot your problems. I suspect
you've got something wrong but I have no idea what - this code works:

Private Sub Text4_KeyDown(KeyCode As Integer, Shift As Integer)
If KeyCode = vbKeyReturn Then
MsgBox "Enter"
ElseIf KeyCode = vbKeyTab Then
MsgBox "Tab"
End If
End sub

Feel free to post back with your code if you still need help.

--
Sandra Daigle [Microsoft Access MVP]
Please post all replies to the newsgroup.


Dave said:
Hello, I want to know how I can tell if the ENTER key was
hit to make a control lose focus (as opposed to TAB or a
mouse click). I've tried the OnKeyPress event, but it
doesn't get triggered by the ENTER key. I've also tried
the OnKeyDown event. It does catch the ENTER key, but
leaves my textbox with a NULL value, even if data appears
to be in it. Can this be done ? Thanks!


.
 
Dave Ruhl said:
Hi Sandra, thanks for the response. Actually my test for
the OnKeyDown event looked just like yours, and yes it
does work. However, it leaves a NULL value in my textbox
field. The OnKeyPress event leaves my data as-is, but
doesn't catch the ENTER key.

The suggestion to use On Key Down *should* work for you..

See my response in M.P.C.
 
Back
Top