Run-time ‘error ‘: 2501

N

Nick hfrupn

I have a problem with a report that if there is no data is returned a message
appears to say No Cards to Print. Press the OK button to close the report and
return to the Main Switchboard. Then the following error comes up;

Microsoft Visual Basic
Run-time ‘error ‘: 2501
The OpenReport action was cancelled

End or Debug

When I press the Debug the following code below is displayed with this line
is highlighted DoCmd.OpenReport "Cards Not Printed", acViewPreview.

I think that as this code has a line referring to the error message 2501 so
that it should not appear. If this is correct then can anyone explain what is
happening, as I don’t understand?
Is it possible to stop this message appearing?

Thanks for any assistance.

Nick


Public Function pfPreviewCards()
On Error GoTo ErrorBit

If pfSetCardColour() Then
pbPrint = False
DoCmd.OpenReport "Cards Not Printed", acViewPreview
Else
MsgBox "There was a Problem with Previewing the Cards", vbCritical,
"Previewing Membership Cards"
End If

ExitBit:
Exit Function

ErrorBit:
If Err = 2501 Then Resume Next Else GoTo ExitBit
Dim strError As String
strError = "Error Information..." & vbCrLf
strError = strError & "Error#: " & Err.Number & vbCrLf
strError = strError & "Description: " & Err.Description
MsgBox strError, vbCritical + vbOKOnly, "Function: pfPreviewCards()"
Resume ExitBit

End Function
 
W

Wayne Morgan

In the Switchboard, put in an error handler that will trap and ignore the
2501 error.

Example:
On Error GoTo MyErrorHandler
'The rest of the code here

ExitHere:
Exit Sub
MyErrorHandler:
If Err.Number = 2501 Then Resume Next
MsgBox 'give the error message here
Resume ExitHere
 
N

Nick hfrupn

Thanks Wayne,
Could you explain what you mean by "the rest of the code here"?
Please excuse my ignorance, as I’m not a power user of Access

Nick
 
W

Wayne Morgan

That would be where you have the code you are already using to open the
report.
 

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