Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to Close a Form with the ESC Key?

Status
Not open for further replies.

number2

Technical User
Oct 25, 2001
284
US
Is it possible to close a form with the ESC key? There is no OnKey function in Access?
 
there is an on key press event though for the form so you could do this

From_Name_OnKeyPress_Event(KeyAscii As Integer)
If KeyAscii = 27 Then
DoCmd.Close Me
End If

I believe 27 is the integer value for the escape key.

HTH
 
Could also use the KeyDown event:

Code:
Sub FormName_KeyDown(KeyCode As Integer, Shift As Integer)  
 
  If (KeyCode = vbKeyEsc) Then
'check and see if key pressed was escape

Code:
   DoCmd.Close acForm, Me

  End If

End Sub


Only bad thing about this is that the form has to have the focus first (I think).


Greg Tammi, Alarm and Telecom Systems(ATS)
E-mail: gtammi@atsbell.com
 
Thanks. I found the easy way: there is a "cancel" property on the object property-other section. When the object with the close form code has this property enabled, the esc key will activate the button. So easy! Why are these things always hidden! I hope this helps others!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top