By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,680 Members | 1,500 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,680 IT Pros & Developers. It's quick & easy.

Error 2501

P: n/a
Hi everyone

It's me again.

I have an access 2000 database with 12 landscape reports which
sometimes have to be FAXED and other times printed, so I have written
the following code and put it in a module to bring up the print
dialog:

Public Function PrintAccess()
DoCmd.RunCommand (acCmdPrint)
'If Err.Number = 2501 Then
'DoCmd.CancelEvent
End If
End Function

This is called from a toolbar called printingtoolbar which is attached
to all the reports. The tool bar actually calls a macro which runs the
code. (not very elegant)`

Everything works fine until the user changes their mind and cancels
the operation, then we get the pesky error 2501.

My difficulty is that I cannot trap this error.

I am trying to find a solution that goes in the function code rather
than one that needs to go in every report.

Regards Smiley Bob
Nov 13 '05 #1
Share this Question
Share on Google+
1 Reply


P: n/a
> Public Function PrintAccess()
DoCmd.RunCommand (acCmdPrint)
'If Err.Number = 2501 Then
'DoCmd.CancelEvent
End If
End Function
To trap the error, you need to set up an error handler.

Public Function PrintAccess()
On Error GoTo CheckError
DoCmd.RunCommand (acCmdPrint)
ExitHere:
Exit Function
CheckError:
If Err.Number = 2501 Then Resume ExitHere
Msgbox Err.Description & vbCrLf & "Error # " & Err.Number, vbOkOnly +
vbCritical, "Error in PrintAccess"
End Function

--
Wayne Morgan
MS Access MVP
"Bob Dydd" <re**************@yahoo.co.uk> wrote in message
news:25**************************@posting.google.c om... Hi everyone

It's me again.

I have an access 2000 database with 12 landscape reports which
sometimes have to be FAXED and other times printed, so I have written
the following code and put it in a module to bring up the print
dialog:

Public Function PrintAccess()
DoCmd.RunCommand (acCmdPrint)
'If Err.Number = 2501 Then
'DoCmd.CancelEvent
End If
End Function

This is called from a toolbar called printingtoolbar which is attached
to all the reports. The tool bar actually calls a macro which runs the
code. (not very elegant)`

Everything works fine until the user changes their mind and cancels
the operation, then we get the pesky error 2501.

My difficulty is that I cannot trap this error.

I am trying to find a solution that goes in the function code rather
than one that needs to go in every report.

Regards Smiley Bob

Nov 13 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.