Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

I Can't undo changes to a textbox 2

Status
Not open for further replies.

ronphx

Programmer
Jun 24, 2004
64
US
This is very frustrating. I'm trying to undo changes to an unbound text box. Just to test this out, I have created a text box (txttest). I have created a simple BeforeUpdate event that does the following:

cancel = true
me.txtest.undo

After I change the entry in the text box and press the tab key, the focus returns to the text box control, but the new value I entered remains in the text box and is highlighted instead of reverting back to the old value.

What am I doing wrong?

Thanks.
 
You should not use the Undo as well as the cancel = true - only one should suffice. Perhaps it is undoing your cancel.

I usually use the DoCmd.CancelEvent statement so do not know if your specific code will work.
 
I think I'm figuring out a little bit of what's happening. I tried only using the cancel = true, and that put the focus back into the text box, but did not change the value, and did not highlight the text (using the DoCmd did the same thing). When I use the undo, the focus goes to the text box and the text is highlighted, but the new value remains.

Could it be that the undo is only preventing the text from updating and not reverting back to the pre-existing value?

 
Can I ask what exactly you are trying to achieve here? If the purpose is to do some action based upon the unbound text box entry, then you should be able to put something in the AfterUpdate event that does the action, then clears the text box.

Alternatively after the cancelevent have you tried to Sendkeys and ESC to clear the box.
 
I have just tried the latter in a form i.e.

DoCmd.CancelEvent
SendKeys "{ESC}"

and it worked great.

Watch out if you have a command button with its Cancel property set to Yes on your form as it could probably fire this event instead.
 
I'm trying to blank out the field so the user can start over. The sendkeys and ESC did the trick. Thanks much.

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top