Jim said:
I've used "isloaded" to verify if a form is open. I'd like to set the On
Change event of a combo box to close all other open forms excep the form
the
combo box is on. Is there a quick way to close all of them, or will I
need
to add the IsLoaded statement for each form that could potentially be
open?
Here's a function that will close all forms except those whose names you
specify as arguments:
'------ start of code ------
Sub CloseAllFormsExcept(ParamArray ExceptForm())
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 ------
Don't use the combo's Change event to call this -- if the user types in the
combo rather than selecting from the list, the Change event will fire with
every keystroke. Instead, use the combo box's AfterUpdate event, and
execute this line of code to close all forms except the one containing the
combo box:
CloseAllFormsExcept Me.Name