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 Wanet Telecoms Ltd on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

BeforeUpdate Cancel Problem 1

Status
Not open for further replies.

wtmckown

Programmer
Mar 19, 2003
121
US
I have an unbound textbox on a form and would like to use it's BeforeUpdate event to validate entries before passing control to an AfterUpdate event. I know I have done this before but my standard method is failing. I am able to use the Cancel argument of the BeforeUpdate event to keep the AfterUpdate event from firing but focus is returned to the text box with the offending value still in it. I want to restore the textbox to the original value if I set the Cancel argument. I normally use ControlName.Undo but it has no effect. I tried sendkeys "{ESC}"....no effect. I tried another invisible textbox that I set to the original value of my textbox in OnEnter but I am simply not allowed to make a change to the textbox value within the BeforeUpdate event. Any ideas how I can Cancel an Update and restore the original value to the textbox?
 
I've had the same problem. Undo simply doesn't work on unbound controls, and if you assign anything to a control's default (Value) property in its BeforeUpdate event, Access gets confused and won't allow it to lose focus. (Setting Cancel also prevents it from losing the focus, but that's expected. You don't want the user to be able to leave the field uncorrected, after all.)

What I do for a workaround is set the TimerInterval to 10 and let the Timer event reload the text box from a saved copy, then set TimerInterval back to 0. The delay is too short for a user to notice.

If I have multiple unbound text boxes, or other uses for the Timer event, I have to set up a scheme so the Timer event knows what it has to do each time, including the possibility that it might have multiple tasks to do in a given event.

Rick Sprague
Want the best answers? See faq181-2886
To write a program from scratch, first create the universe. - Paraphrased from Albert Einstein
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top