Hi everyone,
I am using Access 2010. I have a button on my main form that runs data checks for the user after they import their data. It opens up a mixture of queries, forms and reports.
I need a way to close everything that is open, except the main form. I found code on this site that I tried but I couldn't get to work. I found code on another site that works partially. The code successfully closes all of the open queries and some reports and some forms. But it leaves open about 3 reports and 3 forms that would have to be manually closed.
Am I missing something with the code?
I realize it also closes any open tables as well, which I left in the code in case at some point I add tables to the data checks in the future.
Thanks in advance,
Rhonda
I am using Access 2010. I have a button on my main form that runs data checks for the user after they import their data. It opens up a mixture of queries, forms and reports.
I need a way to close everything that is open, except the main form. I found code on this site that I tried but I couldn't get to work. I found code on another site that works partially. The code successfully closes all of the open queries and some reports and some forms. But it leaves open about 3 reports and 3 forms that would have to be manually closed.
Am I missing something with the code?
I realize it also closes any open tables as well, which I left in the code in case at some point I add tables to the data checks in the future.
Thanks in advance,
Rhonda
Code:
Dim tbl As TableDef
Dim qry As QueryDef
Dim rpt As Report
Dim frm As Form
For Each tbl In CurrentDb.TableDefs
DoCmd.Close acTable, tbl.Name
Next tbl
For Each qry In CurrentDb.QueryDefs
DoCmd.Close acQuery, qry.Name
Next qry
For Each rpt In Application.Reports
DoCmd.Close acReport, rpt.Name
Next rpt
For Each frm In Application.Forms
If frm.Name <> "frmLevel1Switchboard" Then
DoCmd.Close acForm, frm.Name
End If
Next frm
Comment