Report Code Errors

linanderson

Registered User.
Local time
Today, 22:26
Joined
Jul 13, 2002
Messages
17
I have a report dialogue form where users can select a report to run (frmRptDialog).

However I am having some errors when there is no data for a given report and the preview of the report is cancelled.

The code on a given report is:

Private Sub Report_NoData(Cancel As Integer)
MsgBox "There is no data for this report. Cancelling report..."
Cancel = -1

DoCmd.OpenForm "frmRptDialog"

End Sub

Private Sub Report_Close()
DoCmd.Close acForm, "frmReportDateRange"
DoCmd.OpenForm "frmRptDialog"
End Sub

Private Sub Report_Open(Cancel As Integer)
DoCmd.OpenForm "frmReportDateRange", , , , , acDialog, "rptSalesAnalysisByEPCandAgentPD"
If Not IsLoaded("frmReportDateRange") Then
Cancel = True
End If

DoCmd.Close acForm, "frmRptDialog"

End Sub​

The debug opens up the following as an error:

Private Sub ReportID_DblClick(pintCancel As Integer)
RunReport acViewPreview
End Sub

Private Sub RunReport(pintRptView As Integer)
DoCmd.OpenReport Me.ReportID, pintRptView
End Sub

I am trying to identify where the code needs to change. I do want frmRptDialog to close when a report is opened and open again when a report is closed and I wonder if the code is wrong here in the situation where there is no data.

Any quidance would be helpful.

Thanks
 
You need to add error trapping to the sub so you can ignore this particular error. The DoCmd is essentially a macro action and any time it is cancelled it throws error 2501. You can simply ignore this error.
Code:
Private Sub RunReport(pintRptView As Integer)
    On Error GoTo Err_Handler
    DoCmd.OpenReport Me.ReportID, pintRptView
Exit_RunReport:
    Exit Sub

Err_Handler:
Select Case Err.Number
    Case 2501
    Case Else
        MsgBox Err.Number & " - " & Err.Description
End Select
End Sub
 

Users who are viewing this thread

Back
Top Bottom