Error Message when using SetFocus

  • Thread starter Thread starter True.Kilted.Scot
  • Start date Start date
T

True.Kilted.Scot

I've got a text control on my form that holds a date. In the controls
BeforeUpdate event, I perform some validation on the date that has been
entered. What I want to happen is, this:

1. Validate date entered
2. If the date is invalid, display a message
3. Highlight the entered text to prompt user to re-enter a valid
date

To highlight the control, I am using the SetFocus method, i.e.
"txtDateEntered.SetFocus". However, I get the error message:

"You must save the field before you execute the GoToControl action, the
GoToControl method, or the SetFocus method."

The other problem I have is that even if the user is forced back to the
date control, they can simply tab out of the field again, since the
BeforeUpdate event will not be triggered this time, since nothing has
changed.

So, I have two questions:

1. How do I re-select the date control in the event of an
invalid dte being entered
2. How can I force the user to remain in the field, until a
valid date is entered or
the record entry is abandoned

Can someone tell me how to achieve what I want?

Rgds

Duncan
 
The message sounds like it's to do with your using BeforeUpdate - I guess
you're cancelling the action of updating which is leading to the error. I
would normally recommend AfterUpdate instead (you can always get the macro to
clear the date if doesn't validate) BUT if you want this validation to stop
the user tabbing out you'd actually be better with the OnExit event.
 
Back
Top