Count number of query records while in a form

J

Joe M.

I have a form that opens a report. When the query returns zero records I
would like to have a message box appear that there are no records returned
instead of opening the report with no records. Can anyone help?

Thanks,
Joe M.
 
F

fredg

I have a form that opens a report. When the query returns zero records I
would like to have a message box appear that there are no records returned
instead of opening the report with no records. Can anyone help?

Thanks,
Joe M.

Sure. Use the report's OnNoData event. That's what it's for.
1) Code the REPORT's OnNoData event:

MsgBox "There were no records to report on."
Cancel = True

2) Then code the FORM's Command button's Click event (that you used to
open the report):

On Error GoTo Err_Handler
' Your current code to open the report here
' DoCmd.OpenReport "ReportName" etc....

Exit_Sub:
Exit Sub
Err_Handler:
If Err = 2501 then
Else
MsgBox "Error #: " & Err.Number & " " & Err.Description
End If
Resume Exit_Sub
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top