Ignoring no-data reports

  • Thread starter Thread starter Ray
  • Start date Start date
R

Ray

Hi,

I automatically generate a whole bunch of reports to pdf
each week and sometimes a few of the reports hold no
data. Is there a way to skip those reoprts instead of
printing them and having to delete them manually?

thanks
Ray
 
just set the cancel propert of the NoData event to 1
i.e. in the property pages, events tab, choose the 'On No
Data' event, click the '...' button, select the code (not
macro). The VBA code window opens up, and within the
subroutine add the Cancel=1 code :

Private Sub Report_NoData(Cancel As Integer)
cancel=1
End Sub

you might put a message box in (MsgBox "no
data",vbexclamation + vbokonly, "Nothing To Do") to tell you
 
I got this from a previous post from one of the MVP's

You can use the Report's OnNoData event for this. For
example, the following code

'************* Code Start **************
** Put this on the NoData event in report

Private Sub Report_NoData(Cancel As Integer)

MsgBox "No data found! Closing report."

Cancel = True
End Sub

'************* Code End *************

will automatically close the report if there are no
records in the underlying source. However, if you're
opening the report from code behind a form, you need to
handle the error that's generated as a result.

'*********** Code Start ************

Private Sub TestNoData_Click()

On Error Resume Next ' change On errot to this - this
statement is all you need
DoCmd.OpenReport "SomeReport", acViewPreview
If Err = 2501 Then Err.Clear

End Sub

'*********** Code End ************

Jim
 
Back
Top