Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!
  • Students Click Here

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

Microsoft: FoxPro FAQ

Tips -N- Tricks

My Valid or LostFocus Dosn't work by danceman
Posted: 7 Oct 02

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:


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.

Back to Microsoft: FoxPro FAQ Index
Back to Microsoft: FoxPro Forum

My Archive

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close