RunCommand '2501' error in Access 2003 on cancel -

E

excyauseme

Guys this is driving me crazy. I have an Access 2003 mdb with several
RunCommands that have error trapping to handle when the user Cancels a
dialog box. This used to work before all of the latest office 2003
security upgrades. Maybe I'm just not seeing a problem that's so easy
it's going to be totally embarrassing. But I've had this happen to
acCmdPrint as well as acSendReport. Can anyone offer some advice, or
let me know if they've had an issue recently. I will post part of my
code here:

Sub printing(i)
On Error GoTo HandleError

Dim DocName As String
DocName = "rptMiscReports"

<snip snip >

DoCmd.OpenReport DocName, View:=acViewPreview, WindowMode:=acHidden
DoCmd.RunCommand acCmdPrint
DoCmd.Close acReport, DocName

HandleExit:
Exit Sub

HandleError:
Select Case Err.Number
Case 2501 'in case of cancel
Resume Next
Case Else
MsgBox Err.Number & ": " & Err.Description
End Select
Resume HandleExit
End Sub
 
D

Dirk Goldgar

Guys this is driving me crazy. I have an Access 2003 mdb with several
RunCommands that have error trapping to handle when the user Cancels a
dialog box. This used to work before all of the latest office 2003
security upgrades. Maybe I'm just not seeing a problem that's so easy
it's going to be totally embarrassing. But I've had this happen to
acCmdPrint as well as acSendReport. Can anyone offer some advice, or
let me know if they've had an issue recently. I will post part of my
code here:

Sub printing(i)
On Error GoTo HandleError

Dim DocName As String
DocName = "rptMiscReports"

<snip snip >

DoCmd.OpenReport DocName, View:=acViewPreview,
WindowMode:=acHidden DoCmd.RunCommand acCmdPrint
DoCmd.Close acReport, DocName

HandleExit:
Exit Sub

HandleError:
Select Case Err.Number
Case 2501 'in case of cancel
Resume Next
Case Else
MsgBox Err.Number & ": " & Err.Description
End Select
Resume HandleExit
End Sub

So the problem is that you're getting an error message for the 2501
error anyway, despite having error-handling in place to ignore it? In
the VB Editor, click Tools -> Options, and on the General tab, make sure
that the Error Trapping option is set to "Break on Unhandled Errors".
 
B

Brendan Reynolds

Don't you want 'Resume HandleExit' instead of 'Resume Next'? Otherwise, if
the opening of the report is cancelled, the code will attempt to print and
then close a report that is not open.

Also, why open a report in preview mode and hidden in order to print it? Why
not just open it in acNormal mode which will send it straight to the
printer?
 
H

Holly

Hi Brendan. I opened it like that because I don't want to send it
straight to the printer. These reports can be hundreds of pages long,
so it is better for the users to be able to print certain pages. I
tried commenting the OpenReport out, which was dumb, because I got
another error, this time a '2046' Print isn't available now. So I
have to open the report, and in preview hidden mode the user won't see
that and won't bug out, before I can print it.

Thanks for the catch on the Resume. I needed to change that. But it
still is wigging out on the DoCmd.RunCommand acCmdPrint statement, so
it never goes into the error handling part.
 
H

Holly

Dirk said:
So the problem is that you're getting an error message for the 2501
error anyway, despite having error-handling in place to ignore it? In
the VB Editor, click Tools -> Options, and on the General tab, make sure
that the Error Trapping option is set to "Break on Unhandled Errors".

--
Dirk Goldgar, MS Access MVP
www.datagnostics.com

(please reply to the newsgroup)

Dirk you are a GENIUS!!!!!!!!!
Thank you so much - that worked like a charm! We just now upgraded to
Office 2003 (slight time warp..) and people have had all sorts of
problems. I guess that option was set to Break on All Errors after the
upgrade.
 
B

Brendan Reynolds

Here's an alternative way of allowing users to select print options rather
than opening the report hidden ...

DoCmd.SelectObject acReport, "rptTest", True
DoCmd.RunCommand acCmdPrint
 
H

Holly

Cool! Thanks Brendan. That is totally awesome too.
I'm such a noob, it's so great to be able to learn from you experts.
I think this will be much faster, performance wise.
You are the bomb!
 

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