Close Open Reports with Code

G

Guest

I have a list box in my form (frmReports) that allows users to click on
desired reports for preview and printing. The frmReports form stays on top,
so the user can select another report and preview it as well. The intention
of the code in cmdClose is to close all open reports, and close frmReports as
well. I know the For-Next statement works, when I run it in the immediate
window, it correctly displays the names of all open reports. However, the
code is only closing the first open report, not ALL open reports.

How can I modify this code to close ALL open reports?

Private Sub cmdClose_Click()
On Error GoTo Err_cmdClose_Click

Dim rpt As Report

For Each rpt In Reports

DoCmd.Close acReport, rpt.Name, acSaveNo
Next rpt

DoCmd.Close acForm, "frmReports", acSaveNo

Exit_cmdClose_Click:
Exit Sub

Err_cmdClose_Click:
MsgBox Err.Description
Resume Exit_cmdClose_Click

End Sub
 

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