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

lost focus and close button

Status
Not open for further replies.

GShen

MIS
Sep 26, 2002
561
US
I have a field which I do not want the user to exit from without filling it in. I have some vb code on the field using the Lost Focus event which works. However, if the user tries to close the form I just want the code to reset everything back. Is there a way of ascertaining (In my lost focus event) if the user is trying to click on another field (in which case I display an appropriate message and set focus back to the same field again) OR trying to close the form (in which case, I do not want to display anything and I will reset the field back to its original contents) ?

Thanks,

Remember when... everything worked and there was a reason for it?
 
GShen...
How does the user close the form? By a button you created or the normal window close button?
 
Ideas

- Turn off the close button on the form property
- Consider the forms On Close event to do a check
- Rather than use the On Lost focus event, which aint 100% ocker, perhaps use the controls before update event?

Good luck mate!

JB
 
PercyN,
I use the window close button. I changed the code. On the Lost Focus event instead of telling them the field is not filled in, I do that and also set the prior field back immediately. This way if they try and close the form, it does the same thing and all is well. There is no way for them to get around this now. If there is a way to access that this button was hit, I would still like to know for future reference.

Thanks,

Remember when... everything worked and there was a reason for it?
 
What if they try to close the form before reaching your control?

jB
 
JBinQLD,
That is what I was explaining. If they try and close the form it 1st goes to the EVENT LOST FOCUS. I reset the field there before the form gets closed.

Remember when... everything worked and there was a reason for it?
 
so you have an On Lost Focus event for EVERY control on the form?
 
No, just the one field which needs to be filled in when another field is set to YES. When they set this one field to YES (radio button), it immediately send control to an associated combo box. That box has a customer list in it. If they do not enter in a customer I set the prior field back to NO immediately. They have to go hand in hand.

Remember when... everything worked and there was a reason for it?
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top