AutoSkip Report if Null

renenger

Registered User.
Local time
Today, 09:58
Joined
Oct 25, 2002
Messages
117
I have a form that allows the user to print a report for each installer automatically. It prints to the default printer. The problem is this crashes if one of the installers doesn't have any data.


Private Sub Command45_Click()
Dim ctr As Integer

With [Forms]![frmInstallerReports].[Form].[cboInstaller]
For ctr = 0 To .ListCount - 1
[Forms]![frmInstallerReports].[Form].[cboInstaller] = [Forms]![frmInstallerReports].[Form].[cboInstaller].ItemData(ctr)
DoCmd.SetWarnings False
DoCmd.OpenQuery "InstallerComparisonFiscalTable"
DoCmd.OpenQuery "InstallerMetricTableFiscal"
DoCmd.OpenQuery "AppendMetricStatNullsFiscal"
DoCmd.SetWarnings True
DoCmd.OpenReport "rptInstallerMetricChartFiscalAvg"

Next

End With

End Sub

Any ideas on how to prevent the crash?
 
You might try the NoData event of the report! In the report's Design View, in the code editor for rptInstallerMetricChartFiscalAvg place this code:

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

If there's no data, the report for the particular installer should be cancelled.
 

Users who are viewing this thread

Back
Top Bottom