Can't undo a form's TextBox entry that has a validation rule

J

John S. Ford, MD

I'm using Access 2000.

I have a TextBox on a form bound to a field of the form's underlying table
with the following settings:
ValidationRule = Like "####"
ValidationText = "You must enter four consecutive numbers."

The form also has an "Undo" button that is supposed to undo whatever record
entry has been attempted and closes the form. Unfortunately, if the user
enters invalid data into the TextBox, I can't click on the Undo button
because each time I try to do so, the focus leaves the TextBox and the
validation routine gets triggered. When the resulting message box is
closed, the focus goes right back to the Textbox, the Undo button can never
be clicked, the form can therefore never be "undone", and it can't be
closed.

How can I stop this continuous loop from occurring?

John
 
K

KARL DEWEY

Try this --
ValidationRule = Like "####" OR Null

and then just backspace the characters out.
 
D

Dirk Goldgar

John S. Ford said:
I'm using Access 2000.

I have a TextBox on a form bound to a field of the form's underlying table
with the following settings:
ValidationRule = Like "####"
ValidationText = "You must enter four consecutive numbers."

The form also has an "Undo" button that is supposed to undo whatever
record entry has been attempted and closes the form. Unfortunately, if
the user enters invalid data into the TextBox, I can't click on the Undo
button because each time I try to do so, the focus leaves the TextBox and
the validation routine gets triggered. When the resulting message box is
closed, the focus goes right back to the Textbox, the Undo button can
never be clicked, the form can therefore never be "undone", and it can't
be closed.

How can I stop this continuous loop from occurring?


Normally you press {Esc} to undo the invalid entry in the control. Have you
tried that?
 
J

John S. Ford, MD

Yes but then I'd have to depend on my user knowing that. Isn't there a way
of doing this programmatically via a command button?

I know that with VB.net, you can set a button's CausesValidation = False to
prevent a validation routine from occurring in a TextBox elsewhere. This is
typically used with programmer-created "Undo", "Cancel", or "Help" buttons.
Is there no comparable property in VBA?

John
 
D

Dirk Goldgar

John S. Ford said:
Yes but then I'd have to depend on my user knowing that. Isn't there a
way of doing this programmatically via a command button?

I know that with VB.net, you can set a button's CausesValidation = False
to prevent a validation routine from occurring in a TextBox elsewhere.
This is typically used with programmer-created "Undo", "Cancel", or "Help"
buttons. Is there no comparable property in VBA?


No. Of course, you can always have your ValidationText message tell the
user what to do:

"You must enter four consecutive numbers. Correct your entry, or press
{Esc} to undo it."
 
D

Dirk Goldgar

John S. Ford said:
Yes but then I'd have to depend on my user knowing that. Isn't there a
way of doing this programmatically via a command button?


Come to think of it, you can probably do it with a toolbar button -- not a
command button, but a button on the toolbar.
 
A

Albert D. Kallal

John S. Ford said:
Yes but then I'd have to depend on my user knowing that. Isn't there a
way of doing this programmatically via a command button?

I know that with VB.net, you can set a button's CausesValidation = False
to prevent a validation routine from occurring in a TextBox elsewhere.
This is typically used with programmer-created "Undo", "Cancel", or "Help"
buttons. Is there no comparable property in VBA?

Unfortunately we don't have that feature.

However, I not 100% sure if we had the causesVAlidation feature that would
really fix this problem.

Unless you are going to allow the focus to move away from that control then
you can't run the code to do the undo.

The standard windows way is to use the menu bar and go

edit->undo

This works in word, excel, access etc. So, it is very much standard option
in applications that your users will have been exposed to.

I usually build custom menu bars for my applications, and this again solves
the above problem. It also means that you can hide all of the ms-access
interface without have to run special code to hide things.

There is some nice screen shots of access menus in the following link:
I talk about the approach I use to build menu bars here:
http://www.members.shaw.ca/AlbertKallal/Articles/UseAbility/UserFriendly.htm
 

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