docmd.close all objects?

M

Michael Walsh

How I can close all objects?

I know docmd.close will close the default currently active object, but how
can I close anything that's open.

This is a replication function, so I want to close open objects and then
reopen the switchboard which I know is simply docmd.openform
 
A

Allen Browne

Loop backwards through the Forms collection, closing each one, and then
through the Reports collection.

This kind of thing:

Function CloseAllForms()
Dim lng As Long

For lng = Forms.Count - 1 To 0 Step -1
DoCmd.Close acForm, Forms(lng).Name
Next
End Function
 
M

Michael Walsh

Why this does help me close all the forms, I'd like to take that a step
further and close any open reports or tables on the off chance that someone
may be using direct table access. I thought it would be done the same way
but apparently not as this code caused problems.
Dim lng2 As Long
Dim lng3 As Long
For lng2 = Reports.Count - 1 To 0 Step -1
DoCmd.Close acReport, Reports(lng).Name
Next
For lng3 = Tables.Count - 1 To 0 Step -1
DoCmd.Close acTable, Tables(lng).Name
Next
 
A

Allen Browne

You can do exactly the same thing to close reports.

In any database where is matters, you don't let users access tables or
queries directly.
 
Top