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

Cancel the form close event 2

Status
Not open for further replies.

EarS

Programmer
Jun 5, 2002
26
US
I have a method of checking to see if data on a form has been saved. If not then when the form closes it prompt the user to save. When the save routine is entered extensive error checking is done. If there is an error I don't want to save, nor do I want to close the form. How can I cancel the event? I realize I could make my own "exit" button, but the users i am writing this for are stubborn and like the "X in the corner" Thanks in advance...

Matt

Matt_Stanley@imstressed.com
 
Then don't CLOSE the form.

What you need is to put all of the checking etc in the Form_Unload event.

The unload event is cancelable whereas the Close event is NOT cancelable.

Private Sub Form_Unload(Cancel As Integer)
' Your checking code goes here
IF CheckOkay Then
Cancel = False
Else
Cancel = True
MsgBox "Dear User you have erred. I will not let you close this form until you correct the errors you have made"
End If

End Sub


( You might like to mage the error message more user friendly !!! )



When you close a form, the following events occur in this order:

Unload Þ Deactivate Þ Close


'ope-that-'elps.

G LS


 
Works like a charm! I'm a student programmer and am still learning the ropes. Thank's a million!

Matt
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top