(Q) How can I close a report automatically if there's no data
returned by the underlying query?
(A) You can use the Report's OnNoData event for this. For
example, the following code
Private Sub Report_NoData(Cancel As Integer)
MsgBox "No data found! Closing report."
Cancel = True
End Sub
will automatically close the report if there are no records in the
underlying source.
However, if you're opening the report from code behind a form,
you need to handle the error that's generated as a result.
Private Sub TestNoData_Click()
On Error Resume Next
DoCmd.OpenReport "SomeReport", acViewPreview
If Err = 2501 Then Err.Clear
End Sub
|