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 John Tel on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Closing a form by pressing the Esc key 1

Status
Not open for further replies.

chris3942

Technical User
Jul 2, 2003
17
US
How can I close a form by pressing the Esc key?
 
Hi chris3942,

You will need your Form's KeyPreview property set to yes in order for this to work.

If KeyCode = vbKeyEscape Then
DoCmd.Close acForm, Me.Name
End If

This is only an example, you will have to manipulate it to do exactly what it is you want to do.

Note. Personally, I wouldn't use this method, Esc is handy to undo changes to a record.

Bill
 
The "right" way to do it is to add a CANCEL button to the form, and set that button's Cancel property to TRUE. Then, pressing ESC will press the new Cancel button. You should have code beneath the button containing the line
Code:
DoCmd.Close acForm, Me.Name
This technique is also used for an OkeyDokey button; you can set the Default property of the OK button to True. Then, pressing ENTER will cause the OK button to be pressed.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top