ChrisTheAncient
Technical User
Working in Access XP - but will also need to save in A97.
In a working form, I successfully call up a print of a report on some sub-data on that form. All works well using the following...
Private Sub PrintTestDetails_Click()
Me.Refresh
Dim stDocName As String
stDocName = "ReportOnTestResultsByCustomer_Form"
DoCmd.OpenReport stDocName, acPreview, , "[CustomerNumber]=forms!ActiveCustomers!CustomerNumber"
End Sub
BTW, that last DoCmd is all one line!
If, however, that subset of data is empty, all I get is an 'empty' form with inappropriate #Error in places.
If I set an On No Data event on that called up report, using...
Private Sub Report_NoData(Cancel As Integer)
MsgBox "This report contains no data! Cancelling..."
Cancel = True
End Sub
I get my nice message box. But...
I then get an error message and the earlier DoCmd.OpenReport stDocName, highlighted as the buggy line. Unfortunately, in my attempts to cure the error message and try other things, I can't remember what that error message was!
I sincerely hope that makes sense!
Is there a way of cancelling a report (by event programming) if it is empty when it is called up from a form?
TIA
Chris
*************************************
OK, I'm stoopid. But I'm good at it!
*************************************