6/15/10

Do not print a Report if there is no data

If you want to stop the printing of a report that has no data, then there are two steps that you need to do. Firstly, you need to use the Report's NoData event to stop it being printed:

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

The problem with using the NoData event programmatically is that it raises an error in the calling code. Therefore, you will also need to add an error handle to the procedure that opens the Report specifically to trap this error:

Private Sub cmdPrint_Click()
On Error GoTo E_Handle
DoCmd.OpenReport "rptName"
sExit:
Exit Sub
E_Handle:
Select Case Err.Number
Case 2501
Case Else
MsgBox Err.Description, vbCritical + vbOKOnly, "Error: " & Err.Number
End Select
Resume sExit
End Sub


http://www.applecore99.com/rpt/rpt010.asp

No comments: