Dim i As Integer
Dim strForm as String
For i = 1 To CurrentProject.AllForms.Count
If CurrentProject.AllForms(i - 1).IsLoaded Then
strForm = CurrentProject.AllForms(i - 1).Name
If strForm <> "criteria form" And strForm <> "main menu" Then
DoCmd.Close acForm, strForm, acSaveNo
End If
End If
Next i
> I have a criteria form from which I preview/print reports and need to
> close all open forms EXCEPT the criteria form and a main menu prior to
[quoted text clipped - 6 lines]
>
> Thanks!!!
jlute@marzetti.com - 30 Jun 2008 16:34 GMT
Thanks, Dennis! That's a simple and nifty one!
> Dim i As Integer
> Dim strForm as String
[quoted text clipped - 21 lines]
>
> - Show quoted text -
>I have a criteria form from which I preview/print reports and need to
> close all open forms EXCEPT the criteria form and a main menu prior to
[quoted text clipped - 4 lines]
> code to do this? I've searched through the groups and have found some
> very complex codes.
John -
Here's a routine you can call to close all forms except a list you specify
as arguments when you call it:
'----- start of code -----
Sub CloseAllFormsExcept(ParamArray ExceptForm())
' Copyright (c) 2008, DataGnostics LLC
' License is granted to use in your application, so long as
' the copyright notice remains unchanged.
Dim lngFrm As Long
Dim intX As Integer
Dim blnPreserve As Boolean
' Close all open forms except those in the list.
For lngFrm = Forms.Count - 1 To 0 Step -1
With Forms(lngFrm)
blnPreserve = False
For intX = LBound(ExceptForm) To UBound(ExceptForm)
If .Name = ExceptForm(intX) Then
blnPreserve = True
Exit For
End If
Next intX
If blnPreserve Then
' Spare this form
Else
DoCmd.Close acForm, .Name
End If
End With
Next lngFrm
End Sub
'----- end of code -----

Signature
Dirk Goldgar, MS Access MVP
www.datagnostics.com
(please reply to the newsgroup)
jlute@marzetti.com - 30 Jun 2008 16:37 GMT
Hi, Dirk! Long time no see!
Thanks - this is a powerful solution, too! Not sure which I'm going to
use but I certainly appreciate the fact that there's always such
diversity in responses here!
On Jun 30, 10:50 am, "Dirk Goldgar"
<d...@NOdataSPAMgnostics.com.invalid> wrote:
> <jl...@marzetti.com> wrote in message
>
[quoted text clipped - 52 lines]
>
> (please reply to the newsgroup)