Error 2501

A

Alain

Hi to all,

I am having a problem using the NoData event on a report. On occasion there
will be a report being run by a user and that report might have no data when
some filters are being applied.

I use the NoData event to pop a warning msg to the user to select new
criteria
Private Sub Report_NoData(Cancel As Integer)
'cancel report if no recordset
MsgBox "There is no data to report on your criteria." & Chr(13) &
Chr(10) _
& "Please review your choice of selection."
Cancel = True
End Sub

When the report closes it give me the error "2501 the openreport action was
cancelled" at the command line to open the report: DoCmd.OpenReport
stDocName, acPreview, , strCond

Is there something I am missing here ??
Is there a way to correct this error msg

Thanks

Alain
 
T

tina

no, you're not missing anything. cancelling the OpenReport action generates
an error in the procedure that runs the action. you can trap the error and
handle it with error handling code in the procedure, as

On Error GoTo OpenReport_Err

'put here your code that opens the report.

OpenReport_End:
Exit Sub

OpenReport_Err:
If Err.Number = 2501 Then
Resume OpenReport_End
Else
MsgBox Err.Number & " " & Err.Description
Resume OpenReport_End
End If

hth
 
A

Alain

Sorry Tina,
still getting the same error at the docmd line, I even try to clear the
error but no success

'open report from a form that passes criteria thru strCond
DoCmd.OpenReport stDocName, acPreview, , strCond
If Err = 2501 Then Err.Clear

Alain
 

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

Similar Threads


Top