Is there a way to trap Err 2501

Ö

Ömer Ayzan

Friends,

when I cancel the form's unoad event I get the following error.
Run-Time error '2501':
The Close action was cancelled.

But whatever I do I could trap it. Why is that? Any one can help is greatly
appreciated
 
D

Dirk Goldgar

Ömer Ayzan said:
Friends,

when I cancel the form's unoad event I get the following error.
Run-Time error '2501':
The Close action was cancelled.

But whatever I do I could trap it. Why is that? Any one can help is
greatly appreciated

You have to trap it in the procedure that closes the form -- not the
form's Unload event or Close event, but the procedure that (presumably)
calls the DoCmd.Close method against the form. So if, for example, you
close the form from a command button, you might write the code for that
command button something like this:

'----- start of example code -----
Private Sub cmdClose_Click()

On Error GoTo Err_Handler

DoCmd.Close acForm, Me.Name, acSaveNo

Exit_Point:
Exit Sub

Err_Handler:
If Err.Number <> 2501 Then
MsgBox Err.Description, vbExclamation, "Error " & Err.Number
End If
Resume Exit_Point

End Sub
'----- end of example code -----
 
Ö

Ömer Ayzan

Sorry the sentence I mistakenly type should be: But whatever I do I could
NOT trap it.
 
Ö

Ömer Ayzan

Thank you Dirk but what happens when a user chooses to click the close
button.
Ömer
 
D

Dirk Goldgar

Ömer Ayzan said:
Thank you Dirk but what happens when a user chooses to click the close
button.

I'm not sure what you mean. If the user closes the form with the
built-in close button -- the little "x" button in the upper right corner
of the form -- error 2501 should not be raised. If the user closes the
form with a button that you created, then the error should be raised in
the code behind that button, and it must be trapped there, as in the
example I posted.
 

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