Report with no data

B

Bob Richardson

I've designed a report to show all customers with an account balance (after
30 days) > 0. If no customers are in debt and you ask to print this report,
all the fields are filled with "#error" What's the best way to handle this
situation? I'd prefer to print a report with perhaps a simple message
something like "No one is behind in their payments at this time!" rather
than those #error messages.
 
F

fredg

I've designed a report to show all customers with an account balance (after
30 days) > 0. If no customers are in debt and you ask to print this report,
all the fields are filled with "#error" What's the best way to handle this
situation? I'd prefer to print a report with perhaps a simple message
something like "No one is behind in their payments at this time!" rather
than those #error messages.

Why not just cancel the report?
Code the Report's OnNoData event:

MsgBox "Sorry, no records to report on."
Cancel = True

The above will generate error 2501 if you have opened the report from
an event. Trap the error in that event:

On Error Goto Err_Handler

DoCmd.OpenReport "ReportName", acViewPreview

Exit_This_Sub:
ExitSub

Err_Handler:
If Err = 2501 Then
Else
MsgBox "Error #: " & Err.Number & " " & Err.Description
End If
Resume Exit_This_Sub

If you need to generate the paper report anyway, you can instead add
a label to the report "No past due records for this period". Make it
not visible.
Then code the OnNoData event to make it visible and those other
controls not visible.
 
B

Bob Richardson

Thanks Fred. In the NoData event it was easy to make the detail and
reportfooters invisible...they're all contained within one variable :)


NoDataMsg.Visible = True
Detail.Visible = False
ReportFooter.Visible = False
 
Top