Report NoData

  • Thread starter Thread starter David Cowen
  • Start date Start date
D

David Cowen

I would like to create a function for the Report_NoData
Method which suppresses the report from previewing when
there is no data in the report recordsource. See example
below. However, this example does not work correctly.
Does anyone have a solution?

Thanks!

Private Sub Report_NoData(Cancel As Integer)
Call ReportNoData(Cancel)
End Sub

Module basReports:

Option Compare Database
Public intCount As Integer
Sub ReportNoData(intCancel As Integer)
intCount = intCount + 1
If intCount = 1 Then
MsgBox "No data found. ", vbOKOnly
Else
intCancel = 1
intCount = 0
End If
End Sub
 
I would like to create a function for the Report_NoData
Method which suppresses the report from previewing when
there is no data in the report recordsource. See example
below. However, this example does not work correctly.
Does anyone have a solution?

Thanks!

Private Sub Report_NoData(Cancel As Integer)
Call ReportNoData(Cancel)
End Sub

Module basReports:

Option Compare Database
Public intCount As Integer
Sub ReportNoData(intCancel As Integer)
intCount = intCount + 1
If intCount = 1 Then
MsgBox "No data found. ", vbOKOnly
Else
intCancel = 1
intCount = 0
End If
End Sub

How about:
Private Sub Report_NoData(Cancel As Integer)
Cancel = True
End Sub

If you opened this report from a command button on a form, the above
will generate Error 2501.

Trap this error in the code used to open the form.

On Error GoTo Err_Handler
DoCmd.OpenReport "Report Name", acViewPreview

Exit_This_Sub:
Exit Sub
Err_Handler:
If Err = 2501 Then
Else
MsgBox "Error #: " & Err.Number & " " & Err.Description
End If
Resume Exit_This_Sub
 
Do you have a problem using the reports "On No Date"
event? If not, do this: In your report's "On No Data"
event, enter the following:

MsgBox "No data found.", vbExclamation
Cancel = True

Denny G.
 
Back
Top