printing error handling issue? (when clicking cancel get 2501 error)

B

_Bigred

I have a report that when it is closed the

DoCmd RunCommand acCmdPrint occurs ... but of course if the user clicks
cancel, it gives me

a 2501 error.

How & where do I put code to surpress this error. I would just the close
even to run the
DoCmd RunCommand acCmdPrint and if cancel is selected just continue to close
the report?

TIA,
_Bigred
 
B

_Bigred

I understand that I have to do this, I actually don't understand HOW to do
it, and where to put code to accomplish this??

1) What code do I use?
2) Where do I put the code?

Thanks,
_Bigred
 
R

Rick Brandt

_Bigred said:
I understand that I have to do this, I actually don't understand HOW
to do it, and where to put code to accomplish this??

1) What code do I use?
2) Where do I put the code?

Answer for 2) first. You will modify the code you have now so that is WHERE the
code goes.

Answer for 1)...

(line that starts your event code)

On Error GoTo ErrHandler

(your existing code)

Egress:
Exit Sub

ErrHandler:
Select Case Err.Number
Case 2501
'ignore
Case Else
MsgBox Err.Description 'for other errors
End Select
Resume Egress

End Sub

In the example above "ErrHandler" and "Egress" are just line labels so you can
use whatever you want there (those are just the labels I always use).

The idea is that when there are no errors you hit the Exit Sub line so the code
in the Error Handler is not run. When there is an error your code will jump
down to the ErrHandler label and then execute the code it finds there. The
Resume line at the end sends the code back up to your code exit point (it is
better to always have the code terminate at the same spot rather than just
letting it fall through to your End Sub line).
 
B

_Bigred

Thanks much Rick, I'll try that solution out and post back results.

Thank You for your time & help,
_Bigred
 

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