On no data

  • Thread starter Thread starter Anne
  • Start date Start date
A

Anne

I am selecting a job from a combobox and click to print a report. If there
is no data, I get an error message.
The on no data event does not seem to work with a report because I get this
message:

run-time error '2585'
This action can't be carried out while processing a form or report event.

How can I prevent a visual basic error message and display a custom message
that there is no data for this report?
 
I am selecting a job from a combobox and click to print a report. If there
is no data, I get an error message.
The on no data event does not seem to work with a report because I get this
message:

run-time error '2585'
This action can't be carried out while processing a form or report event.

How can I prevent a visual basic error message and display a custom message
that there is no data for this report?

A Report's OnNoData event works just dandy for me.

Private Sub Report_NoData(Cancel As Integer)
MsgBox "This report has no records to report on."
Cancel = true
End Sub


When you have a question about an event (or almost anything else)
always include the actual code or examples if applicable.
We can't see your database.
 
Thanks Fred,
I had been trying to correct this issue in the wrong spot, I tried to
correct the issue after the error message from the form and the changes to
the report did not stick. I now opened the report by itself and added the no
data event and it works.
 
Thanks Fred,
I had been trying to correct this issue in the wrong spot, I tried to
correct the issue after the error message from the form and the changes to
the report did not stick. I now opened the report by itself and added the no
data event and it works.

Anne,
In addition to canceling the report in the report's OnNoData event, be
aware that if you have opened that report using code in an event, i.e.
a command button's click event, cancelling the report will cause an
error# 2501 on the form code. You need to trap that error on the form,
otherwise you will get an un-needed error message.

Private Sub CommandButtonName_Click()

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
End Sub
 
Back
Top