Custom Enter Key action? (VBA newbie)

  • Thread starter Thread starter Jon22
  • Start date Start date
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.
 
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
 
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/
 
Back
Top