Trapping "Esc" in VBA

M

MikeB

Usually when one presses "Esc" twice on a form, any updates to the
current record is backed out. Unfortunately, I need to revert the
changes to an unbound control at the same time.

I cannot seem to find an event that is driven for undo by pressing
escape twice, except the Key Press event. I'm worried that if I trap
the "Esc" key in this event, the backout will not occur, yet I'd like
to reset the unbound control at the same time as the other changes are
reverted.

Any advice from the folks here?
 
S

Stefan Hoffmann

hi Mike,
Usually when one presses "Esc" twice on a form, any updates to the
current record is backed out. Unfortunately, I need to revert the
changes to an unbound control at the same time.

I cannot seem to find an event that is driven for undo by pressing
escape twice, except the Key Press event. I'm worried that if I trap
the "Esc" key in this event, the backout will not occur, yet I'd like
to reset the unbound control at the same time as the other changes are
reverted.

Any advice from the folks here?
In Access 2003+ the form itself has an undo event, which is fired when
the undo occurs.



mfG
--> stefan <--
 
B

Brian

Does the value of that control depend on the value of other controls? If so,
can you make the unbound control a calculated control? That way, it would
revert automatically when other controls are changed back.
 
M

MikeB

hi Mike,




In Access 2003+ the form itself has an undo event, which is fired when
the undo occurs.

mfG
--> stefan <--

Unfortunately I'm writing this in an older version of Access - Access
2002. :(
 
S

Stefan Hoffmann

hi Mike,
Unfortunately I'm writing this in an older version of Access - Access
2002. :(
Check it, i'm not sure for Access XP. Otherwise use the forms Key Press
event and set Key Preview to true.



mfG
--> stefan <--
 
M

MikeB

Does the value of that control depend on the value of other controls? If so,
can you make the unbound control a calculated control? That way, it would
revert automatically when other controls are changed back.

It's a two-way street (in a manner of speaking). When the record is
initially filled in, I use the value in this combo box ("White",
"Black" or "Draw") to calculate the point score for each of the White
and Black Players (1 point for a win, 1/2 point for a draw). The
scores are fields in the table.

When the record is displayed, I have a routine that looks at the score
of White (Black's score can be inferred from White's score) and sets
the combo box accordingly.

Unfortunately, it doesn't seem as if the result of the double "esc"
drives any of the events that I'm listening to so that I can
recalculate the value of the result combo box. I have an "undo" button
that does it, I'm just trying to be consistent.

My concern is that if I trap the double "esc", I'm interfering with
the natural way Access handles it and then I'm not going to get the
results I want or that I'm going to add a lot of processing by having
to look at all the possible keystrokes to handle whatever is coming
from the keyboard.

If there is a way to change the combo box I'd be more than happy to do
this. I'm going to read up and see if I can find anything under
"calculated control," since I only know about bound and unbound
controls.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top