I have a report that If there is not data to print, I would like to display a
message indicating that there are no record to print. I'm able to use the
nodata event to display the message but I still open the blank report in
preview mode. I included a Docmd command to quit the report but it does not
work.
My question is; is there anyway that I can display the message and avoid the
blank preview reprot from showing?
Your guidance and knowledge share will be appreciated.
Luis
John Spencer - 28 Mar 2008 15:08 GMT
Normally, all you need to do is set Cancel = True in the On No Data event.
If you are calling the report from somve VBA code you will have to trap the
error that is generated.

Signature
John Spencer
Access MVP 2002-2005, 2007-2008
Center for Health Program Development and Management
University of Maryland Baltimore County
.
>I have a report that If there is not data to print, I would like to display
>a
[quoted text clipped - 11 lines]
>
> Luis
fredg - 28 Mar 2008 16:16 GMT
> I have a report that If there is not data to print, I would like to display a
> message indicating that there are no record to print. I'm able to use the
[quoted text clipped - 8 lines]
>
> Luis
In the Report's NoDataEvent, write:
MsgBox "There are no records."
Cancel = True
If you have used code to open the report, this will raise Error 2501
"You have canceled ....etc."
Trap this error in the code event you have used to open the report.
On Error GoTo Err_Handler
DoCmd.OpenReport "ReportName", acViewPreview
Exit_Sub:
Exit Sub
Err_Handler:
If Err = 2501 Then
Else
MsgBox "Error #: " & Err.Number & " " & Err.Description
End If
Resume Exit_Sub

Signature
Fred
Please respond only to this newsgroup.
I do not reply to personal e-mail