How do I replace #Error in access report with another statement?

J

JWeaver

I get an "#Error" message on a report that doesn't have any records to show.
Can I change this message to something like "There are no records to display
on this report"?
 
D

David Mulholland

Sure...on your report's On No Data event, you can add a short msgbox that
will prompt you with that remark...

Private Sub Report_NoData(Cancel As Integer)

MsgBox "There are no records to display on this report."
DoCmd.CancelEvent

End Sub
 
J

JWeaver

Thanks, that worked!
--
JWeaver


David Mulholland said:
Sure...on your report's On No Data event, you can add a short msgbox that
will prompt you with that remark...

Private Sub Report_NoData(Cancel As Integer)

MsgBox "There are no records to display on this report."
DoCmd.CancelEvent

End Sub
 
J

JWeaver

Instead of having the message box pop up, is it possible to have a line
printed on the report that indicates there aren't any records? This way, I
would have a report page that indicates this because I might need to include
it with reports that I give to my Supervisor.

Thanks!
 
F

fredg

Instead of having the message box pop up, is it possible to have a line
printed on the report that indicates there aren't any records? This way, I
would have a report page that indicates this because I might need to include
it with reports that I give to my Supervisor.

Thanks!

Then don't cancel the OnNoData event.
Add a label to the report.
Caption: "There were no records to report on."
Set it's visible property to No
Name this label "NoRecs"

Code the Report's OnNoData event:
' MsgBox "No records found." ' This message is optional
Dim ctl as Control
For each ctl in Me.Section(0).Controls
ctl.Visible = False
Next
Me.NoRecs.Visible = True

The above code will make all of the other controls in the detail
section Not Visible (so you don't get #error displayed), and will make
the label visible.
If you wish to hide ALL of the controls on the report, change
For each ctl in Me.Section(0).Controls
to
For each ctl in Me.Controls
 

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