Don't want to print a report with no data

  • Thread starter Thread starter Maggie
  • Start date Start date
M

Maggie

I'm trying to prevent a report from printing whenever
there is no data in the underlying recordset. Not sure
what I'm doing wrong.
When I enter this code:
Cancel = True
MsgBox "There is no data for the key you entered."

into the "OnNoData" event of my report, I get error msg
" The OpenReport action was cancelled"
Run-time error '2501'

back in the calling form at this line of code:
DoCmd.OpenReport "projSearchAdminByArch", acViewPreview, ,
strSQL
 
In the calling form, use an error handler and in the error handler tell it
that if the error is 2501 then ignore it.

If Err.Number = 2501 Then Resume Next
 
Back
Top