DoCmd.Close multiple report choice

G

Guest

I have a form that opens with info for different reports and when the form is
closed I want it to close whichever report is open that time
Is it possible to do. I tried the following and it will close the form and
the first line but if I am in the Estimate report it doesn't close that one.
Any suggestions? Thanks!

DoCmd.Close
DoCmd.Close acReport, "rptPO_1"
DoCmd.Close acReport, "rptEstimate_1"
DoCmd.Close acReport, "rptPO"
 
G

Guest

Put the three lines to close the reports in the form's Close event procedure.
That way it should close the report(s) however the form is closed.

Ken Sheridan
Stafford, England
 
G

Guest

Thanks for the response I have tried it in the close and the clik event of
the form and neither will close anything past the first line...

???
 
G

Guest

If you put the code in the form's Close eventprocedure you don't put the
first line there; just the 3 lines to close the report:

DoCmd.Close acReport, "rptPO_1"
DoCmd.Close acReport, "rptEstimate_1"
DoCmd.Close acReport, "rptPO"

The line to close the form can go in a button's Click event procedure if you
wish, but by having the other three lines in the form's Close event procedure
they will execute however the form is closed, whether its from a button, by
clicking the X in the top right of the form or from the menu or toolbar.

Ken Sheridan
Stafford, England
 
G

Guest

You're right!!... and were all along I had an underscore in one of the rpt
names that was keeping it from working. Thanks!
 
W

Whitney

I'm trying to do this with a report that has 2 subreports. I continue to get
the parameter field pop up and if I cancel those, the main report still
opens, but is blank. How can I prevent the report from opening and really
abort the request with just clicking the cancel button on the form.


DoCmd.Close acReport, "subrpt_Returns"
DoCmd.Close acReport, "subrpt_Wrhs"
DoCmd.Close acReport, "rpt_Daily"

If I use the last command I get the debug error.
 
J

John Spencer

First, you don't close sub-reports. They are controls on the main report.

Since I am not sure where you are attempting to accomplish this, all I can
suggest is that you add error code to your routine to trap the error.


Perhaps something like



On Error GoTo ProcError

DoCmd.Close acReport, "rpt_Daily"

Exit Sub
ProcError:
If Err.Number = 2501 then
'Do nothing
else
MsgBox Err.Number & ": " & Err.description,,"Whoa, dude!"
End If
End Sub


John Spencer
Access MVP 2002-2005, 2007-2008
The Hilltop Institute
University of Maryland Baltimore County
 

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

Similar Threads


Top