Canceling Form_Unload get MessageBox from Access runtime...




I've searched for posts that address this, but failed to find any - so sorry
if I'm being repetitive.

I have an unbound form, and do a check in Form_Unload to see if the user
really wants to close the form. If the user does want to cancel the form's
close, when I set "Cancel = True" in the code, Access pops a message box
saying "the closed action was cancelled".

How can I make this message go away?


Brendan Reynolds

This will ignore that error, but display a message if any other error occurs

Private Sub Form_Unload(Cancel As Integer)

On Error GoTo ErrorHandler
If MsgBox("Really quit?", vbYesNo) = vbNo Then
Cancel = True
End If

Exit Sub

'2501 = action was canceled.
If Err.Number <> 2501 Then
MsgBox "Error " & Err.Number & ": " & Err.Description
End If
Resume ExitProcedure

End Sub

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