How do I report no data found in query, other than a blank page?

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I am writting a general query builder and need to report to the user that
their query did not return any records. Just a blank piece of paper in not
acceptable.
 
You may want to put a function behind your form ....

(untested but it would be similar)
Private Sub myReport OnLoad()
If myRS.EOF Then
MsgBox "There were no results for this query. Please try again with
more data"
DoCmd.Close acReport, "MyReport"
End If
End Sub

hth
 
Or, use the OnNoData event of the report.


Private Sub Report_NoData(Cancel As Integer)
MsgBox "This report contains no data"
Cancel = True
End Sub


You might get an error on the line of code that you used to open the
report.


Chris Nebinger
 
You can also (depending on you application), catch the error before the
report is run by checking the query for records:

If (CurrentDb.OpenRecordset("Query2").RecordCount = 0) Then
MsgBox ("There are no records available")
Else
open query or report
End If
 

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

Back
Top