VBA to close all the forms

M

Martin

Is there any VBA sentence to close all the opening(active) forms ?

Thank you.

Martin
 
D

Douglas J Steele

Dim intLoop As Integer

For intLoop = (Forms.Count - 1) To 0 Step -1
DoCmd.Close acForm, Forms(intLoop).Name
Next intLoop
 
V

Van T. Dinh

You can code something like:

****
Dim intIndex As Integer

For intIndex = Forms.Count -1 To 0 Step -1
DoCmd.Close acForm, Forms(intIndex).Name, acSaveNo
Next intIndex
****
 
M

Martin

No, these two methods are not good enough. I want a VBA sentence which is
belong to the Access itself -- that's, one sentence can do, not necessary
for sevral sentences.
 
D

Douglas J Steele

Sorry, there isn't one. None of the collections in Access have a "Close All"
method associated with them.

Why does it matter, though, whether it's 1 line or 5 as long as it
accomplishes what you're trying to do?
 
M

Martin

I am creating a MIS, "Close all" used quite often, if "close all" is
available, I will be very happy !!!

:)
 
V

Van T. Dinh

What Doug and I suggested is all in Access VBA.

This is the Sub I actually tested on:

****
Public Sub CloseAllForms()
Dim intIndex As Integer

For intIndex = Forms.Count - 1 To 0 Step -1
DoCmd.Close acForm, Forms(intIndex).Name, acSaveNo
Next intIndex
End Sub
****

Whenever you want to close all Forms, you simply use the statement

CloseAllForms
 
Top