No Data Report

D

dimpie

Hi - when a report does not have data, i would like to print a report that
says "NO Data"

I tried doing this in the no data event of the report, but this is not
working.
Here is my code

Private Sub Report_NoData(Cancel As Integer)

DoCmd.OpenReport "rpt_MP_Infract_NO_Data", acViewPreview
Cancel = True
End Sub

When i run this code, it will open this report that syas "NO Data" and goes
back to the same line i am calling the report that has data to open and gives
me a runtime error.

If this is confusing, please give me a fresh approach as how i could do this.

Thanks a lot!!!
 
F

fredg

Hi - when a report does not have data, i would like to print a report that
says "NO Data"

I tried doing this in the no data event of the report, but this is not
working.
Here is my code

Private Sub Report_NoData(Cancel As Integer)

DoCmd.OpenReport "rpt_MP_Infract_NO_Data", acViewPreview
Cancel = True
End Sub

When i run this code, it will open this report that syas "NO Data" and goes
back to the same line i am calling the report that has data to open and gives
me a runtime error.

If this is confusing, please give me a fresh approach as how i could do this.

Thanks a lot!!!

If you only wish to have a report print out that says "There is no
data to report on." (or something like that), you can do that using
the same report that has the no data.

Add a label to the Report Header Section with a caption of whatever it
is you wish to say.
Name this label 'lblNoData'.
Make it Not Visible.

Code the report's OnNoData event:

Private Sub Report_NoData(Cancel As Integer)
Dim c as Control
For each c in Me.Section(0).Controls
c.Visible = false
Next c
lblNoData.Visible = True

End Sub

If the report has no data in it, the label will become visible, and
all of the other controls in the detail section will not be visible
(so that they won't show '#error').
Since you have not set Cancel = True, you can just print the same
report.

Note: if any of the other sections have controls that you do not wish
to show if the report has no data, use the same For Each ... Next
method to hide the controls in that section.
 
D

dimpie

Thanks a lot!!! it is working. But now a tiny little concern.

How can i hide a subreport?

your help is much appreciated.

Thank you!!!
 

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

Top