Scott Morris wrote:
One should be very careful when trying to use the losefocus event for this.
I'd agree with Scott on this, for additional reasons. IMHO, it's a bad user experience to get a data validation pushed into your face when (for example):
- you're trying to press the Cancel button (focus moves from DataWindow to button)
- you're switching to another app (maybe in the middle of the edit)
- you're closing the window, and you haven't confirmed yet that you're intending to save the changes
I'd agree with coding something that gets called from ItemChanged (assuming you want edit-time validations, not save-time), and put AcceptText() in places like
- the Clicked event of the OK or Save button
- the GetFocus of any other DataWindow or any other control that isn't part of abandoning your changes
- CloseQuery (although coding things so that you don't get the error prompt before you've confirmed that you want to save is a little more involved)
Good luck,
Terry.