Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to count records after filtering a recordset

Status
Not open for further replies.

Druck

Technical User
Jun 19, 2011
2
US
I have designed a form that allows a user to generate a report and use various criteria to filter that report. The report has a pre-designed SQL statement for a recordsource (some of these already require a "WHERE" clause in the SQL string). Based on the drop-down selections, I create a string called "strFilter" and place that in the DoCmd.OpenReport(strReportName,acViewPreview,,strFilter).

Everything works fine until there are no records left after the filter is applied. I need a way to count the records after applying the filter so that I can interject with a Message Box if there are no records to display on the report.

Any ideas? Thanks!
 
Disregard...found out that what I thought was a problem was not my problem. I actually had a different reference to a Subroutine spelled wrong which was sending my form in the wrong direction. Oops.
 
It is better to use On No Data <event procedure> in Report


Private Sub Report_NoData(Cancel As Integer)
MsgBox "No Record", vbOKOnly + vbInformation, "NO Data"
'Set Cancel = True for preventing opening report if not set as true then message will display and report will open
Cancel = True
End Sub
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top