closing all forms except switchboard

B

bicyclops

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.
 
A

Allen Browne

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
 

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

Top