Stolem from a post by Terry Kreft from 1998....
Try these three scenarios out (Counter is a text field on the form which has
the focus)
1) KeyPreview for the form is set to Yes
Private Sub Form_KeyDown(KeyCode As Integer, Shift As Integer)
If KeyCode = 27 Then MsgBox "form Key" : KeyCode = 0
End Sub
Private Sub Counter_KeyDown(KeyCode As Integer, Shift As Integer)
If KeyCode = 27 Then MsgBox "Field key"
End Sub
Pressing the esc key results in a message box popping up saying "form Key"
2) KeyPreview for the form is set to No
Private Sub Form_KeyDown(KeyCode As Integer, Shift As Integer)
If KeyCode = 27 Then MsgBox "form Key" : KeyCode = 0
End Sub
Private Sub Counter_KeyDown(KeyCode As Integer, Shift As Integer)
If KeyCode = 27 Then MsgBox "Field key"
End Sub
Pressing the esc key results in a message box popping up saying "Field Key"
3) KeyPreview for the form is set to Yes
Private Sub Form_KeyDown(KeyCode As Integer, Shift As Integer)
If KeyCode = 27 Then MsgBox "form Key"
End Sub
Private Sub Counter_KeyDown(KeyCode As Integer, Shift As Integer)
If KeyCode = 27 Then MsgBox "Field key"
End Sub
Pressing the esc key results in a message box popping up saying "form Key"
followed by a msgbox saying "Field key"