Open Rpt Action was cancelled

K

Karen

I have a report that prompts for recipient name. I have a msg that "There's
no data." in the on no data event of my report.

I put a command button (through the wizard) on my form to open the report.
However, when there's no data, I get two messages: the one above as well as
the "Open rpt action was cancelled" mesage.

I tried to put code to handle the error in the command button's error event
(as earlier recommended by Ken Sheridan) but there's no "On Error" event
listed on the even tab of the button's properties. As a matter of fact, none
of the commands that I have on the form, have this option.

Please advise on how to get rid of this second error message. Thanks in
advance.
 
F

fredg

I have a report that prompts for recipient name. I have a msg that "There's
no data." in the on no data event of my report.

I put a command button (through the wizard) on my form to open the report.
However, when there's no data, I get two messages: the one above as well as
the "Open rpt action was cancelled" mesage.

I tried to put code to handle the error in the command button's error event
(as earlier recommended by Ken Sheridan) but there's no "On Error" event
listed on the even tab of the button's properties. As a matter of fact, none
of the commands that I have on the form, have this option.

Please advise on how to get rid of this second error message. Thanks in
advance.

I'm sure you miss-understood Ken's suggestion. A Command button
doesn't have an error event. You trap the error in the ERROR HANDLER
of whatever code you are opening the report with.
Here's how.

First, code the report's OnNoData event, as follows:

Private Sub Report_NoData(Cancel As Integer)
MsgBox ""There's no data."
Cancel = True
End Sub


Then code the Click event on the form like this:

Private Sub CommandName_Click()
On Error GoTo Err_Handler

DoCmd.OpenReport "ReportName", acViewPreview

Exit_CommandName_Click:
Exit Sub

Err_Handler:
If Err = 2501 Then
Else
MsgBox "Error #: " & Err.Number & " " & Err.Description
End If
Resume Exit_CommandName_Click
End Sub

Change CommandName to whatever the actual name of the command button
is.

PS. The form itself has an Error event, but that's not what you need
here.
 
J

James A. Fortune

Karen said:
I have a report that prompts for recipient name. I have a msg that "There's
no data." in the on no data event of my report.

I put a command button (through the wizard) on my form to open the report.
However, when there's no data, I get two messages: the one above as well as
the "Open rpt action was cancelled" mesage.

I tried to put code to handle the error in the command button's error event
(as earlier recommended by Ken Sheridan) but there's no "On Error" event
listed on the even tab of the button's properties. As a matter of fact, none
of the commands that I have on the form, have this option.

Please advise on how to get rid of this second error message. Thanks in
advance.

Since you are using a form to drive the report, why not have just a
little more code in the form to check to see if the SQL for the report's
RecordSource returns any records/rows before trying to open the report?
Testing for no rows versus some rows using say, a recordset, seems to
be at least as fast as what the NoData event would have to do. That way
you don't need to rely on error handling at all to cancel the report.

The recipient name could also go in a combobox on the form so that the
query can refer to it instead of having Access prompt the user when the
report is opened. Using LimitToList on the combobox could prevent
trying to run the report with an invalid recipient name due to choosing
someone thats not in the table or due to a typo. The code that
evaluates the SQL to test for records/rows can also refer to the value
in the combobox. BTW, it's also possible to change the default message
and behavior of a combobox that has its LimitToList property set to True
in case you find it annoying.

James A. Fortune
(e-mail address removed)
 

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