Checking for Undo

M

Mary Fetsch

In Access 2000, I have a form with several fields that are summed. Each time
a number is entered into one of these fields, the number is added to the
field's sum. If the user decides to press Esc twice to clear the record, I
want to clear those sums. But I haven't been able to figure out a way to
identify that the user has done that. Any ideas will be greatly appreicated!
 
W

Wayne Morgan

The Undo event of the form fires when the user presses Esc twice. It will
also fire if the user presses Esc once (undo the field) if that was the only
dirty field on the form. You can set the value of your textboxes in the Undo
event.
 
M

Mary Fetsch

Thanks for your response. I don't see an Undo event on the form or on a text
field. My database is an Access 2000 project (.adp), but I don't see that
event on a .mdb database I have either.
 
W

Wayne Morgan

Open the form in Design View, open the Properties sheet, make sure the combo
box at the top of the properties sheet says "Form", go to the Event tab, you
will see "On Undo" as the 7th item in the list. Set it to [Event Procedure]
and click the ... button that appears on the right side of the box.
 
M

Mary Fetsch

I did exactly as you said, and I don't have an On Undo event on the form or
Open the form in Design View, open the Properties sheet, make sure the combo
box at the top of the properties sheet says "Form", go to the Event tab, you
will see "On Undo" as the 7th item in the list. Set it to [Event Procedure]
and click the ... button that appears on the right side of the box.

--
Wayne Morgan
MS Access MVP


Mary Fetsch said:
Thanks for your response. I don't see an Undo event on the form or on a
text
field. My database is an Access 2000 project (.adp), but I don't see that
event on a .mdb database I have either.
 
W

Wayne Morgan

It is there for a form. I created an adp file to check to see if it is there
in that also, and it is. Has your Event tab scrolled down and is covering
the desired line?
 
M

Mary Fetsch

I do not have an Undo event. I checked with my supervisor to see if I was
missing something, and he agrees that I don't have it. He has it in his
Access 2003, but I do not have it in my Access 2000.
 
W

Wayne Morgan

Ok, looking at Access 2000, try setting the form's Key Preview (event tab)
to Yes, in the KeyPress event check for KeyAscii = 27, this is the Esc key,
and react accordingly. When you receive the key 27, check to see if the form
is "dirty" (If Me.Dirty = True Then) to see if the form has been undone. You
may need to set a form level variable that gets set to True in the form's
Dirty event so that you know the form was really undone and it wasn't just
someone pressing the Esc key for no reason. Set this variable back to False
when you run your code in your undo code.
 
M

Mary Fetsch

I discovered I can use my recordset's RecordChangeComplete event to
accomplish what I want. When adReason = adRsnUndoAddNew or adRsnUndoUpdate,
I can recalculate my totals. Thanks for all your help. (If you can think of
a better way to do this, please let me know.)
 
Top