PDA

View Full Version : Run time error 2501



jmentor
08-22-2005, 07:02 AM
Despite the following

Private Sub Report_NoData(Cancel As Integer)
MsgBox "No data to Display"
Cancel = True
End Sub

I still get "Run time error 2501 the OpenReport
action was cancelled.
Does anybody have any suggestions to remove
this message.

Tommy
08-22-2005, 07:10 AM
Why do you have Cancel defined as an Integer and set it as a Boolean?

jmentor
08-22-2005, 07:27 AM
Tommy

What's wrong with that ?
Cancel as True or False
Anyway, I picked it up from here
http://office.microsoft.com/en-us/assistance/HP051874191033.aspx

Tommy
08-22-2005, 08:01 AM
I understand true can be evaluated to anything other than 0 and false can be evaluated to 0. But why define it as an integer? and then set it to to true. IMHO it should be:

Private Sub Report_NoData(Cancel As Boolean)
MsgBox "No data to Display"
Cancel = True
End Sub

But of course it will always return true, so it will always cancel.

Now to the problem, the sub posted, according to the link that was posted, is an event. It gets fired only when there is no data, not when the report was canceled. So I would suggest some code in the Error event, that clears the error and deactivates the report.

jmentor
08-22-2005, 08:16 AM
Tommy

Thats what I'am after.

eed
08-25-2005, 01:05 PM
Tommy

Thats what I'am after.

jmentor,
I don't receive the 2501 error when my No Data event is triggered, so I can't verify that this will solve the problem in your circumstances, but you could try:


Private Sub Report_NoData(Cancel As Integer)
On Error GoTo HandleErrors
MsgBox "No data to Display"
Cancel = True
ExitHere:
Exit Sub
HandleErrors:
Select Case Err.Number
Case 2501
Resume ExitHere
Case Else
MsgBox Err.Description & " (Error: " & Err.Number & ")"
Resume ExitHere
End Select
End Sub

xCav8r
09-02-2005, 09:08 PM
What's the status on this? Still need help? Solved?