(Leo) Error on Form to open report

G

Guest

I have a form for get the user's criteria for running a report. on that
report, when there is no data (blank), it prompts user that there is no data
, and stops openning the report. But this event (no data on report) causes an
error on my form and the debuger stops on that statment which open the report;
DoCmd.OpenReport ReportName...
I dont why the open report command causes an error when the report is empty??
 
J

Jason Marshall

Because there is no report.. ie.. The data is required for the report to
happen?
 
G

Guest

You could trap the error, something like:

Private Sub cmdRunReport_Click()

On Error GoTo Err_cmdRunReport_Click

DoCmd.OpenReport "rptMyReport", acViewPreview

Exit_cmdRunReport_Click:
Exit Sub

Err_cmdRunReport_Click:
' Error 2501 = "Open Report action was canceled" (no records)
If Err.Number = 2501 Then
' Do nothing
Else: msgbox "Error #: " & Err.Number & " " & Err.Description
Resume Exit_cmdRunReport_Click
End If

End Sub

You haven't mentioned the mechanics of how you are opening the report. I
will assume that you have a parameter query, a form (frmParameter) to specify
the criteria, and that the parameter query uses controls on frmParameter as
its criteria, something like is described in Help.
The above example assumes a command button (cmdRunReport) on a form
somewhere. Clicking the command button opens rptMyReport. The On Open event
for the rptMeReport is to open a frmParameter, which prompts for the query
parameters. A command button on frmParameter makes the form invisible, and
the report opens according to the specified parameters. Instead of the
remark 'Do Nothing in the code you could have a message box informing the
user that there are no records. If you need more information you will need
to post more details of how you have this set up.
 
G

Guest

thank you for your reply,
let me explain more;
On the form, I have also two option buttons that determins which report
should be opened by the DoCmd.OpenReport command. On the other side, on the
NoData event of each report , I have this Sub for showing the user that there
is no data to be shown, and stops openning the report;
Private Sub Report_NoData(Cancel As Integer)
MsgBox ("No Data Found!")
Cancel = True
End Sub
this procedure works properly, when the reports is run without a form, but
when I use the form, then that command encounters with an error when it wants
to opent an empty report.
Should I delete this procedure on the report, and insert it somehow on the
form to do the same job?
If I should how?
 

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