Excape Key as a Button

  • Thread starter Thread starter Simon
  • Start date Start date
S

Simon

I would like a button on the acccess form that does the same as what
an excape does on a keyboard

Whats the code to do this

On Click
?????????




Thanks
 
hi Simon,
Simon said:
I would like a button on the acccess form that does the same as what
an excape does on a keyboard
What does the escape key on a keyboard?
Whats the code to do this
Take a look at the KeyPreview property of your form:

http://msdn.microsoft.com/en-us/library/aa196210(office.11).aspx

You may call

Me.Undo

or

Dim ac As Access.Control

Set ac = Me.ActiveControl
If Not ac Is Nothing Then
ac.Undo
End If

depending on your needs.


mfG
--> stefan <--
 
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
'====================================================
 
Back
Top