Report crashes when there are no records

  • Thread starter Thread starter Sophie
  • Start date Start date
S

Sophie

hello

I have a command button that uses DoCmd.OpenReport... etc... to print a
report in preview mode. The report's record source is called qryData. On
occassion, this query has no records, though I don't know this when I click
the command button. In this case (no records in qryData) the program hangs.

How can I prevent an attempt to print when there are no records in the
underlying query?

thank you
 
You could try code like:
If DCount("*","qryData") > 0 Then
DoCmd.OpenReport .....
End If

Otherwise most of us would place some code in the On No Data event of the
report.
 
Any idea why this report could make the whole program hang, Duane? I've
never had seen this happen before, I just see error messages when reports
have no data.

Evi
 
There might be some code running in the report. Otherwise I have seen some
postings where various keep together and new page property combinations seem
to bring a report to its knees.
 
You also need to trap for error 2501 in the error handler for the procedure
from which the report is opened. Even if you use the report's NoData event,
Access will throw the error because the report was canceled.
 
Thanks Duane, I'll bear that it mind.
Evi
Duane Hookom said:
There might be some code running in the report. Otherwise I have seen some
postings where various keep together and new page property combinations seem
to bring a report to its knees.
 
Back
Top