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

  • Thread starter Thread starter JWeaver
  • Start date Start date
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"?
 
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
 
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
 
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!
 
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
 
Back
Top