Report crashes when there are no records

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
 
D

Duane Hookom

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.
 
E

Evi

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
 
D

Duane Hookom

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.
 
K

Klatuu

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.
 
E

Evi

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.
 

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

Similar Threads


Top