Custom Enter Key action? (VBA newbie)

J

Jon22

Is it possible to have some code run when a user leaves a field by clicking
the Enter Key? I know there is the After Update event but I would not want
this particular code to run if say the user just left this field by clicking
away - only when the Enter key is hit while in the field.
 
K

Ken Snell MVP

You can use the KeyDown event of the control to test if the Enter key was
pressed, and then run your code if it was.

Private Sub NameOfControl_KeyDown(KeyCode As Integer, Shift As Integer)
If KeyCode = 13 And Shift = 0 Then
' The Enter key was pressed
' put your code here
End If
End Sub
 
J

Jon22

Brilliant. Thank you.

Ken Snell MVP said:
You can use the KeyDown event of the control to test if the Enter key was
pressed, and then run your code if it was.

Private Sub NameOfControl_KeyDown(KeyCode As Integer, Shift As Integer)
If KeyCode = 13 And Shift = 0 Then
' The Enter key was pressed
' put your code here
End If
End Sub

--

Ken Snell
<MS ACCESS MVP>
http://www.accessmvp.com/KDSnell/
 

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