Close all reports

L

Leslie Isaacs

Hello All

I have a form with a combobox and various buttons: the user opens various
reports in preview by clicking on the appropriate buttons.
The reports use the value in the combobox as a parameter.
The problem is that sometimes the user does not close a previewed report
before changing the value in the combobox, and then when they click the
button for the report that is already open they do not get the correct
report.
Is there a way to put some code behind the combobox (as the before or after
update event) that will close all the reports that are open?
This strikes me as the best way to solve the problem ... if there is a
command that will do it!

Hope someone can help
Many thanks
Les
 
G

Guest

Use the DoCmd.Close method to close the reports (see VBA Help on Close method
for details)
You will just need to keep track of which reports are open so you can close
them.
 
M

Marshall Barton

Leslie said:
I have a form with a combobox and various buttons: the user opens various
reports in preview by clicking on the appropriate buttons.
The reports use the value in the combobox as a parameter.
The problem is that sometimes the user does not close a previewed report
before changing the value in the combobox, and then when they click the
button for the report that is already open they do not get the correct
report.
Is there a way to put some code behind the combobox (as the before or after
update event) that will close all the reports that are open?
This strikes me as the best way to solve the problem ... if there is a
command that will do it!


Ignoring the issue of multiple instances of a single report,
you can close all open reports by looping through the
Reports collection.

Dim k As Integer
For k = Reports.Count -1 To 0 Step -1
DoCmd.Close acReport, Reports(k).Name, acSaveNo
Next k
 
L

Leslie Isaacs

Klatuu

Thanks for your reply.

I have used the DoCmd.Close method before, but as far as I'm aware I can
only use this when I know the name of the open report/s.

I don't think I can keep track of which reports are open.

I was hoping for a way of just closing whichever reports happen to be open -
without having to identify them.

Is this possible?

Thanks again

Les
 
L

Leslie Isaacs

Marshall

Thanks for your reply: your code worked brilliantly!!
That will be very useful for me.

Thanks again
Les
 
L

Leslie Isaacs

Klatuu
I have just seen and used Marshall's method, which gave me exactly what I
wanted.
Thanks again for your help.
Les
 

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