Prevent opening a report if no data to show
Wednesday, May 20th, 2009We can prevent a report open if no data to show, and for this we use two forms depending on the version of Access:
1 - All versions of ACCESS
Place the code below in the properties of the report, the event 'Enabling'
Use the event Enabling (Activate) Report:
Private Sub Report_Activate ()
If DCount ("*", Me.RecordSource) = 0 Then
MsgBox "No records to display" vbDefaultButton1, "Error!"
AcReport DoCmd.Close, "report name"
End If
End Sub
2 - From version 7 (Access 95) was added the event 'if no data', then we can urilizar the following code:
Private Sub Report_NoData (Cancel As Integer)
MsgBox "No data in the report.", VbInformation, "Error!"
Cancel = True
End Sub
To see running download the example: Prevent opening report





























