Report queries belong in Reports

  • Thread starter Thread starter Jonathan Scott via AccessMonster.com
  • Start date Start date
J

Jonathan Scott via AccessMonster.com

I'm in Access97, and I'm trying to keep my queries tied to my Reports by
actually keeping the query inside the report.

Problem is, I am not able to gracefully quit my report if there is in fact
no data applicable for the report. DoCmd.Quit() just quits the application;
DoCmd.CancelEvent() causes an error to appear, confusing the user (there
was no real error); Exit Sub just prints the report filled with errors
because there is no data to fill in the form with.

Is there a graceful way to keep report queries in their proper place,
inside reports, and not cause confusing problems for the user by gracefully
exiting?

Jonathan Scott
 
I'm in Access97, and I'm trying to keep my queries tied to my Reports by
actually keeping the query inside the report.

Problem is, I am not able to gracefully quit my report if there is in fact
no data applicable for the report. DoCmd.Quit() just quits the application;
DoCmd.CancelEvent() causes an error to appear, confusing the user (there
was no real error); Exit Sub just prints the report filled with errors
because there is no data to fill in the form with.

Is there a graceful way to keep report queries in their proper place,
inside reports, and not cause confusing problems for the user by gracefully
exiting?

Jonathan Scott

Code the Report's OnNoData event:

MsgBox "There are no records to show in this report."
Cancel = True

If the report was opened via an event on a form, this will cause an
error.
Trap the error in the event that opened the form:

On Error GoTo Err_Handler
DoCmd.OpenReport "ReportName", acViewPreview

Exit_This_Sub:
Exit Sub
Err_Handler:
If Err = 2501 Then
Else
MsgBox "Error #: " & Err.Number & " " & Err.Description
End If
Resume Exit_This_Sub
 
Thanks fredg, the OnNoData event fixed it.

Jonathan Scott
 
Back
Top