Dirk:
Thanks for reply. Still having a bit of trouble. I call the open
report from a modul. There is a command button on a form that that
when clicked calls a report after filtering the records. Some
filitered results have no records. I'm trying to display the message
box without the runtime error 2501 when a report has no records
The code on the on click
event of the button is
________________________________________________________________________
____
______________
Private Sub btnPrintFilteredReport_Click()
Dim frm As Form
Dim strReportName As String
Set frm = Me
strReportName = Me!lstReports
Call frankPrintFilterReport(frm, strReportName)
End Sub
________________________________________________________________________
____
______________
The code
for the Module is:
Function frankPrintFilterReport(frm As Form, strReportName As String)
Dim strCriteria As String
stFilterValue = frm.cmbFilterValue
stConvFilterValue = StrConv(stFilterValue, vbLowerCase)
If blnYesNo = True Then
If stFilterValue = "yes" Or stFilterValue = "true" Or
stFilterValue = "on" Then
frm.cmbFilterValue = -1
ElseIf stFilterValue = "no" Or stFilterValue = "false" Or
stFilterValue = "off " Then
frm.cmbFilterValue = 0
Else
End If
End If
strCriteria = "((([" & stFormDataSource & "].[" & stFilterField &
"]) = Forms.[" & frm.Name & "].cmbFilterValue))"
DoCmd.OpenReport strReportName, acViewPreview, ,
WhereCondition:=strCriteria
End Function
________________________________________________________________________
____
_______________
Any furhter assistance is greatly appreciated.
Dirk Goldgar said:
BlankI have a report with as message box in it that returns when no
records are found. Specifically, how do I add error-handling to the
procedure in order to trap error 2501.
my code is as follows and placed in the [On no data] property of the
report:
MsgBox " Your filter selection option has no records to display."
Cancel = True
I assume by the above that you mean the OnNoData property is set to
"[Event Procedure]", and your code is in an event procedure for this
event, so it looks like this:
Private Sub Report_NoData(Cancel As Integer)
MsgBox " Your filter selection option has no records to
display."
Cancel = True
End Sub
This being the case, you need to trap the 2501 error (action
cancelled) in the code procedure that opens the report, not in any
event procedure in the report itself. So if you are opening the
report with some code along the lines of:
DoCmd.OpenReport "ReportName", acViewPreview, , strCriteria
then you need an error-handler there:
On Error GoTo Err_Handler
' ... other code ...
DoCmd.OpenReport "ReportName", acViewPreview, , strCriteria
' ... maybe other code ...
Exit_Point:
Exit Sub
Err_Handler:
If Err.Number = 2501 Then
Resume Next
Else
MsgBox Err.Description, vbExclamation, "Error " & Err.Number
Resume Exit_Point
End If
End Sub