Access Event for Escaping out of a form

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.

E
LVL 5
eantarAsked:
Who is Participating?
 
eantarAuthor Commented:
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,
E
0
 
DatabaseMX (Joe Anderson - Microsoft Access MVP)Database ArchitectCommented:
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.

mx
0
 
Jeffrey CoachmanMIS LiasonCommented:
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)
0
 
eantarAuthor Commented:
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.
0
 
eantarAuthor Commented:
This was the only way I could make it work.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.