VBA to close all the forms

  • Thread starter Thread starter Martin
  • Start date Start date
M

Martin

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

Thank you.

Martin
 
Dim intLoop As Integer

For intLoop = (Forms.Count - 1) To 0 Step -1
DoCmd.Close acForm, Forms(intLoop).Name
Next intLoop
 
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
****
 
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.
 
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?
 
I am creating a MIS, "Close all" used quite often, if "close all" is
available, I will be very happy !!!

:)
 
So create a subroutine that does it, and call the subroutine!
 
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
 

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

Back
Top