Closing multiple report previews

K

Kirk P.

I've got a form that launches 2 reports in report preview mode. I would like
BOTH reports to close when clicking the X, or when clicking Close on the
Preview toolbar. How can I accomplish this?
 
A

Allen Browne

In the Close event procedure of Report1:

If CurrentProject.AllReports("Report2").IsLoaded Then
DoCmd.Close acReport, "Report2"
End If

And vice versa.
 
K

Kirk P.

It's throwing a 2585 run-time error - this action can't be carried out while
processing a form or report event.
 
A

Allen Browne

The idea is to put the name of the other report in there (not the one that
is already closing.)
 
K

Kirk P.

I think I've got it right. Here's the code

In Close Event of rptMissingBU

Sub Report_Close()
If CurrentProject.AllReports("rptMissingGLAcct").IsLoaded Then
DoCmd.Close acReport, "rptMissingGLAcct"
End If
End Sub
________________________________________________________

In Close Event of rptMissingGLAcct

Sub Report_Close()
If CurrentProject.AllReports("rptMissingBU").IsLoaded Then
DoCmd.Close acReport, "rptMissingBU"
End If
End Sub

Still getting that pesky error message.
 
A

Allen Browne

Good you have it working.

I imagine something else is causing the error.

It would be good to track and down and deal with it properly, but you can
suppress it with error handling. If that's a foreign concept, see:
Error Handling in VBA
at:
http://allenbrowne.com/ser-23a.html
 
K

Kirk P.

Got it. Thanks again for the help!

Allen Browne said:
Good you have it working.

I imagine something else is causing the error.

It would be good to track and down and deal with it properly, but you can
suppress it with error handling. If that's a foreign concept, see:
Error Handling in VBA
at:
http://allenbrowne.com/ser-23a.html
 

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