mistux Site Admin
Joined: 25 Jun 2004 Posts: 1042 Location: South Bend, Indiana USA
|
Posted: Wed Dec 03, 2008 5:51 pm Post subject: Close report automatically if no data found |
|
|
(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
Code: | '************* Code Start *************
Private Sub Report_NoData(Cancel As Integer)
MsgBox "No data found! Closing report."
Cancel = True
End Sub
'************* Code End ************* |
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.
Code: | '*********** Code Start ************
Private Sub TestNoData_Click()
On Error Resume Next
DoCmd.OpenReport "SomeReport", acViewPreview
If Err = 2501 Then Err.Clear
End Sub
'*********** Code End ************ |
|
|