Error trapping

G

Guest

I have the error code 2501 appearing when I Cancel a form closing (which I
believe is to be expected). To prevent the message showing I have wittten an
error handler routine:
If err <> 2501 Then
MsgBox err.Number & " " & err.Description
End if
Just to make things interesting Access 2003 now throws an error 3021 at me.
It occurs when I close my form without saving and I am asked if I want to
save changes (if there have been any). If I select Cancel the error 3021
occurs. It doesn't appear to affect any of the code running though. Mind you,
if I then repeat the exact same procedure, everything runs as expected with
the 3021 not appearing again. Very strange! Is this a bug? Is there a fix?
I've given up trying to find out what's causing it. But my question is: What
is the correct syntax to use to change my error trapping code to ignore both
errors? Thanks
 
A

Allen Browne

Error 3201 occurs when it tries to save the record. That only happens if
something is being entered.

If you are trying to close the form without saving the record being entered:
If Me.Dirty Then
Me.Undo
End If
DoCmd.Close acForm, Me.Name
 

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