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

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
itmtsnAsked:
Who is Participating?

[Webinar] Streamline your web hosting managementRegister Today

x
 
Jupiler78Connect With a Mentor Commented:
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
 
itmtsnAuthor Commented:
Thanks very much, worked a treat!
0
 
Jupiler78Commented:
Glad I could help.
thanks for the points & grade.

Jupiler78
0
All Courses

From novice to tech pro — start learning today.