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

Stopping Form_Close

Status
Not open for further replies.

Guest_imported

New member
Jan 1, 1970
0
Is there a way to stop the Form_Close from happening? In my situation I'm using If statements during Form_Close to check if data has been entered. If not it brings up msgbox asking user to add data. But when I press ok on the msgbox the form continues to close. I need to stop it until all the Ifs have been checked.

thanks!
 
Since it's form_close event, it certainly will proceed to close the form.

My suggestion is, if you'd like certain field to have data, set the rule in its' validation rule property and message in its' validation text property. That way, you don't have to wait until they try to close the form to validate data, but soon they leave it blank. You can set its' default value to blank, so that it might get attention first when the user tries to fill up another field.

Tin Tin
 
Add a DoCmd.CancelEvent under your Msgbox line in the code so that the close event is canceled and doesn't happen.

HTH Joe Miller
joe.miller@flotech.net
 
Do whatever checks you want to do on form close, setting a boolean to true if you don't want the form to close, then on form_Unload add the following..

If blncheck = true then
Cancel = true
endif
 
The form unload event triggers before the close event. Loonpants's suggestion did not work for me. Perhaps I was doing something incorrect?

Gary
gwinn7
 
OK, here is what seems to work...

Perform your validation checks in the Form_Unload event. Then, if the conditions are satisfied, use the Docmd.CancelEvent command to halt the form from closing.

Example:

Private Sub Form_Unload(Cancel As Integer)

If Me.Text0 = "Cancel" Then DoCmd.CancelEvent

End Sub

Let me know if you have another (better?) way of doing this.

Gary
gwinn7
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top