Learn how to a build a cloud-first strategyRegister Now


Access Event for Escaping out of a form

Posted on 2012-09-10
Medium Priority
Last Modified: 2012-09-16
Hi all,

I have an label that displays a certain text  when a field value on a bound form is true, and a different text when the value is false . The label works as a toggle. When the label is clicked the fld value turns true and the lable says "On". Clicked again, the field value is false and the label says "Off".

My problem comes when someone hits the Esc key in the middle of updating.

If they click the label when the value is false it goes from "Off" to "On". This is before the form is updated. If they hit the Esc key, the value reverts back to False, but the Label stays "On".

Does anyone know how to trap for the Esc key? Or how to handle the situation?

Any help would be greatly appreciated.

Question by:eantar
  • 3
LVL 75
ID: 38384608
Like so:

Private Sub Form_KeyDown(KeyCode As Integer, Shift As Integer)
    If KeyCode = vbKeyEscape Then KeyCode = 0
End Sub

Be sure the Form's KeyPreview property is set to Yes.

LVL 74

Expert Comment

by:Jeffrey Coachman
ID: 38385768
My guess is that you could also force a save after the lable is clicked :
    Docmd.Runcommand accmdsaverecord

Why not just use a Checkbox control for True and False (where you have many more events, like "AfterUpdate", where things like this typically happen)
...Instead of clicking the label
(which may not be obvious to a new user)

Author Comment

ID: 38387381
But guys, is there no way to trap for escaped entry? No event? Current doesn't fire. I wondered if there was a new event in 2010. Just curious.

Accepted Solution

eantar earned 0 total points
ID: 38387686
Hey guys,

Found a solution. Converted the label to a text box, which requeries when you hit the Esc key. The text box's control source is set to a function that does all the work and set's the text accordingly.

All the best,

Author Closing Comment

ID: 38402905
This was the only way I could make it work.

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say 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

This article describes a method of delivering Word templates for use in merging Access data to Word documents, that requires no computer knowledge on the part of the recipient -- the templates are saved in table fields, and are extracted and install…
We live in a world of interfaces like the one in the title picture. VBA also allows to use interfaces which offers a lot of possibilities. This article describes how to use interfaces in VBA and how to work around their bugs.
In Microsoft Access, learn different ways of passing a string value within a string argument. Also learn what a “Type Mis-match” error is about.
In Microsoft Access, learn how to use Dlookup and other domain aggregate functions and one method of specifying a string value within a string. Specify the first argument, which is the expression to be returned: Specify the second argument, which …
Suggested Courses

810 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