Loop backwards through the Forms collection, and use the Name to determine
which to leave open.
This kind of thing:
For i = Forms.Count -1 to 0 Step -1
If Forms(i).Name <> "Switchboard" Then
DoCmd.Close acForm, Forms(i).Name
End If
Next
--
Allen Browne - Microsoft MVP. Perth, Western Australia.
Tips for Access users -
http://allenbrowne.com/tips.html
Reply to group, rather than allenbrowne at mvps dot org.
"bicyclops" <(E-Mail Removed)> wrote in message
news:91FA294E-C4F7-4F80-80FC-(E-Mail Removed)...
> I've set up the following code
>
> Dim frm As Access.Form
> For Each frm In Application.Forms
> If frm.Caption <> Screen.ActiveForm.Caption Then frm.Close
> Next
>
> The idea is to close all forms but the switchboard when the corresponding
> button on the switchboard is pressed. I keep getting an error message: Run
> Time Error 2465, and the program complains about the frm.close statement.
>
> Is there a way to make this work or is there a better way to close all
> forms?
>
> Thanks in advance.
>