Form Close on Key press in Access

You can close or control any Form event from your Keyboard. In this sample the Form closes when ‘ESC’ key is pressed. To set this feature on any Form, first set the ‘Key Preview’ property in the Event Tab of the Form’s property sheet. Then set the Event Procedure for the ‘On Key Press’ event. Write the following code within Procedure:

If KeyAscii=27 Then
End If

The above code checks for the Ascii code returned by the key pressed on the Keyboard. The Ascii code for ‘ESC’ key is 27. So if the Ascii code is 27 then close the form. Similarly you can monitor other keys.
IMPORTANT: The sample file included is in MS Access 2007. If you would like sample file of lower versions, e-mail me at and I will e-mail you the file. Please don’t forget to mention the version of MS Access you are using.


  • Form Close on Key press in Access (27778-20517-FormClose1.accdb)
  • Comments

    No responses found. Be the first to comment...

  • Do not include your name, "with regards" etc in the comment. Write detailed comment, relevant to the topic.
  • No HTML formatting and links to other web sites are allowed.
  • This is a strictly moderated site. Absolutely no spam allowed.
  • Name: