how to cancel unload

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
 
P

PC Datasheet

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.
 
R

Rod

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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top