>> button has focus

J

Jonathan

Hi, Access 2003. Among a bunch of controls on a form is a textbox and command
button. This textbox does some data validation in its textbox_afterupdate
event. The command button is an 'Undo' that restores values to the last save.

A user may make a change to the text box value and then click 'Undo'. The
problem is that I want to skip the after_update event when a user clicks
'Undo'.

How can my code know that the user has clicked 'Undo'?

Any ideas or recommendations appreciated. :)

Many thanks,
Jonathan
 
D

Dirk Goldgar

Jonathan said:
Hi, Access 2003. Among a bunch of controls on a form is a textbox and
command
button. This textbox does some data validation in its textbox_afterupdate
event. The command button is an 'Undo' that restores values to the last
save.

A user may make a change to the text box value and then click 'Undo'. The
problem is that I want to skip the after_update event when a user clicks
'Undo'.

How can my code know that the user has clicked 'Undo'?

Any ideas or recommendations appreciated. :)


You cannot prevent the text box's AfterUdate event from running when the
user clicks on the button, if the button is on the form. If the button is
on a toolbar, that's okay, because the form's active control never changes
from the text box. But if you move the form's focus to some other control
on the form, the AfterUpdate event will fire.

The only way I can think of to get around this, and I really don't think
it's worth it, is to use MouseMove events, of the button and of the form
section containing the button, to detect whether the mouse pointer is over
the button or not and set a module-level flag variable to indicate that.
Then, in the text box's AfterUpdate event, you might check the flag variable
and, if the flag indicates that the mouse pointer was over the button,
bypass the rest of the code in the event.

I haven't tested that, but it seems to me that it might work. However, I
can't speak to how reliably it would work, and I believe it's much to
complicated to be worth it. Instead, I would either put the Undo button on
a toolbar, or else just teach users to press the Escape key.
 
D

Dale Fye

What is it in the textboxes AfterUpdate event that you are trying to avoid?

I usually include a "Cancel" button on most of my data entry forms as well
(many of my users do not seem to be trainable regarding use of the Escape
button). As long as this button and the textbox are on the same form (the
button is not in a subform), using the Cancel button to implement the Undo
method will restore the data in all of the controls on that form to the
previous value of the control. On the other hand, if the user clicks on an
object that is outside of the data entry form (maybe a control in the main
form if it is in a subform) then the Forms Before and AfterUpdate events will
fire, and the Cancel button will have no effect.
 
D

Dirk Goldgar

On the other hand, if the user clicks on an object that is outside of the
data entry form (maybe a control in the main form if it is in a subform)
then the Forms Before and AfterUpdate events will fire

This is not strictly true. To clarify, if the focus changes from a (dirty)
main form to a subform, or from a (dirty) subform to its parent form (or
it's parent's parent), then the Before_ and After_Update events will fire.
But if the focus changes to an unrelated form, or to a toolbar item, then
those events will *not* fire. The original form or subform will remain
dirty.
 
D

Dale Fye

yeah, that's what I meant.

;-)

----
Dale



Dirk Goldgar said:
This is not strictly true. To clarify, if the focus changes from a (dirty)
main form to a subform, or from a (dirty) subform to its parent form (or
it's parent's parent), then the Before_ and After_Update events will fire.
But if the focus changes to an unrelated form, or to a toolbar item, then
those events will *not* fire. The original form or subform will remain
dirty.

--
Dirk Goldgar, MS Access MVP
Access tips: www.datagnostics.com/tips.html

(please reply to the newsgroup)
 

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