Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Seeing if records for report exist 1

Status
Not open for further replies.

bernie10

Technical User
Sep 13, 2004
219
US
Hey guys,
What's the easiest way to check if at least one record exists before opening a report (from a form). The report is based on a query which is in turn based on certain values from the form.

So what I want is

Code:
If Recordsexist then  [green]'What would this line be???[/green]
    DoCmd.OpenReport "MyReport", acViewPreview
    DoCmd.Close acForm, "MyForm"
Else 
    Msgbox ("No Records exist for this report.")
End If

Thanks for the help,
Collen
 
You could do something priot to opening a report, use one of the domain aggragates with the same criteria as is used on the report, open a recordset, but the easiest, is probably to use the on no data event of the report. Just give the user a message, then add the line Cancel = True.

In the calling sub, be sure to handle the 2501, for instance like this:

[tt]on error resume next
DoCmd.OpenReport "MyReport", acViewPreview
if err.number=2501 then
err.clear
end if
on error goto <your error handler>[/tt]

Roy-Vidar
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top