Say your user is entering a new record and is sitting on a field that requires validation. After entering bad data for that field, but before moving focus to another field, the user clicks the Save button on your toolbar or chooses Save from the menu. Whooshùthe data is saved, including the bad data. What happened?
In VFP, as in FoxPro 2.x, the Valid routine for a text field doesn't execute until focus leaves that field. Clicking a button on a toolbar or picking a menu item doesn't change focus and therefore doesn't fire the Valid method or the LostFocus method, of course. (In fact, a toolbar never has focus, which lets you do pretty cool things.)
Why does it behave this way? Because we want it to. It feels wrong in this situation, but suppose the toolbar or menu item the user chose was Select All or Paste. We sure wouldn't want the focus to change (and the Valid and LostFocus methods to fire) in that case.
So how do we make sure the data gets validated? Simpleùmake sure focus changes. One way to do this is to reset focus to the same field:
_SCREEN.ActiveForm.ActiveControl.SetFocus()
Since menus and toolbars don't get the focus, _SCREEN.ActiveForm is still the same form as before. We just set the focus back to the object that had it, which triggers that control's Valid, LostFocus, When and GotFocus methods.
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.