I would like to have a procedure that I can call to close any open forms,
except the one I just loaded.
Does anyone know an easy way to do this?
Copy the following to a standard module (not a module behind a form or report):
'*************CODE START
Public Sub subCloseAllBut(frm As Form)
Dim iFrms As Integer
Dim iIndex As Integer
'Get forms' highest index number (zero based)
iFrms = Forms.Count - 1
For iIndex = iFrms To 0 Step -1
'If referenced form is not "Me" then close
If Forms(iIndex).Name <> frm.Name Then
DoCmd.Close acForm, Forms(iIndex).Name
End If
Next
End Sub
'*************CODE END
Now, call this sub from the desired location using the following syntax:
subCloseAllBut Me
If you want to close all other forms upon opening certain forms, then call this
sub from those forms' "On Open" event procedures.