Solved

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

Posted on 2008-10-18
3
890 Views
Last Modified: 2013-11-28
Hi,

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.

Jon
0
Comment
Question by:itmtsn
  • 2
3 Comments
 
LVL 8

Accepted Solution

by:
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"
        DoCmd.Close
    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

Regards,

Jupiler78
0
 

Author Closing Comment

by:itmtsn
ID: 31507424
Thanks very much, worked a treat!
0
 
LVL 8

Expert Comment

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

Jupiler78
0

Featured Post

Simplifying Server Workload Migrations

This use case outlines the migration challenges that organizations face and how the Acronis AnyData Engine supports physical-to-physical (P2P), physical-to-virtual (P2V), virtual to physical (V2P), and cross-virtual (V2V) migration scenarios to address these challenges.

Question has a verified solution.

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

Have you ever wanted to restrict the users input in a textbox to numbers, and while doing that make sure that they can't 'cheat' by pasting in non-numeric text? Of course you can do that with code you write yourself but it's tedious and error-prone …
I see at least one EE question a week that pertains to using temporary tables in MS Access.  But surprisingly, I was unable to find a single article devoted solely to this topic. I don’t intend to describe all of the uses of temporary tables in t…
Familiarize people with the process of retrieving data from SQL Server using an Access pass-thru query. Microsoft Access is a very powerful client/server development tool. One of the ways that you can retrieve data from a SQL Server is by using a pa…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

777 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