how to cancel unload

  • Thread starter Thread starter Rod
  • Start date Start date
R

Rod

I have captured the form unload event and want to be able to stop the form
closing if I am not happy.
How do I do this.

ie.

Private Sub Form_Unload(Cancel As Integer)

If Something Then
Don't Close form
Else
Go ahead and carry on closing
Endif

End Sub

many thnaks

Rod
 
Private Sub Form_Unload(Cancel As Integer)
If Something Then
Cancel = True
Endif
End Sub

Note: You don't need the Else part.

You also need this for your Cloce button:

On Error Resume Next
DoCmd.Close

Without the above code, if you press the Close button and Close is cancelle in
the UnLoad event, you'll get an error message.
 
Thanks for the prompt reply

cheers

Rod


PC Datasheet said:
Private Sub Form_Unload(Cancel As Integer)
If Something Then
Cancel = True
Endif
End Sub

Note: You don't need the Else part.

You also need this for your Cloce button:

On Error Resume Next
DoCmd.Close

Without the above code, if you press the Close button and Close is cancelle in
the UnLoad event, you'll get an error message.
 
Back
Top