Access VBA code: Pressing Esc to run code and exit the form

Posted on 2008-10-18
Last Modified: 2013-11-28

I have a form which records via a barcode scanner products purchased for an honesty bar. In the old system after scanning the items wanted you hit the Escape key which recorded the purchases against your account and logged you out.

Do I use the "On Key Press" Event within the purchsing form and if so how do I tie the code to the pressing of the Esc key?

Thanks in adavnce.

Question by:itmtsn
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2

Accepted Solution

Jupiler78 earned 500 total points
ID: 22748557
Hello itmtsn,

If that is what you want, use the On Key Down on the form:
    If KeyCode = vbKeyEscape Then
        MsgBox "escape key"
    End If

that code captures the escape key on the form event.
Just on the form properties set on tabblad event - key preview to yes



Author Closing Comment

ID: 31507424
Thanks very much, worked a treat!

Expert Comment

ID: 22755446
Glad I could help.
thanks for the points & grade.


Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

It’s been over a month into 2017, and there is already a sophisticated Gmail phishing email making it rounds. New techniques and tactics, have given hackers a way to authentically impersonate your contacts.How it Works The attack works by targeti…
In Part II of this series, I will discuss how to identify all open instances of Excel and enumerate the workbooks, spreadsheets, and named ranges within each of those instances.
In Microsoft Access, learn how to “cascade” or have the displayed data of one combo control depend upon what’s entered in another. Base the dependent combo on a query for its row source: Add a reference to the first combo on the form as criteria i…
Using Microsoft Access, learn some simple rules for how to construct tables in a relational database. Split up all multi-value fields into single values: Split up fields that belong to other things into separate tables: Make sure that all record…
Suggested Courses
Course of the Month9 days, 9 hours left to enroll

624 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question