Count number of query records while in a form

  • Thread starter Thread starter Joe M.
  • Start date Start date
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.
 
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
 
Back
Top