Do you want to undo the entire form? Or do you want to undo the last
change only?
The escape key does one of two things.
If you are in a control and have changed data but not moved off the
control (lost focus), then pressing the escape key undoes the change in
the control. If you press the escape twice in this situation, then the
second press of the escape key undoes all the changes to the form.
If you are in a control, but have not made any change to the control's
text property, then pressing escape ONCE undoes the all the changes to
the form.
So what do you want to do?
Undo the form changes whenever the button is pressed is a simple one
line statement.
Me.Undo
Undo the changes to a control, when the button is pressed is a bit more
complex.
First you have to determine the previous control, then you have to check
to see if that control is bound to a field source, then you reset the
control's value to its OldValue.
Dim ac as Access.Control
Set Ac = Screen.PreviousControl
ac.Value = ac.OldValue
You will need to trap errors with code this simple. First, if there was
no previous control that will generate an error. Second if the control
has no value or OldValue property that will generate another error.
'====================================================
John Spencer
Access MVP 2002-2005, 2007-2009
The Hilltop Institute
University of Maryland Baltimore County
'====================================================