Check and Close All Forms Except Switchboard

E

Ed Bloom

How do I get the following pseudo code working?

procedure cmdbtnCloseThisForm( )

Loop
Get List of All Open Forms
If NOT SwitchBoard
Close
end-if
end Loop
If Switchboard NOT Open
Open SwitchBoard
end if

Thank you in advance.
 
A

Allen Browne

Something like this:

Dim lngI as Long
Dim strDoc As String
Const strcSwitchboard = "Switchboard"

For lngI = Forms.Count -1 To 0
strDoc = If Forms(lngI).Name
If strDoc <> strcSwitchboard Then
DoCmd.Close acForm, strDoc
End If
Next

If Not CurrentProject.AllForms(strcSwitchboard).IsLoaded Then
DoCmd.OpenForm strcSwitchboard
End If

(The last part requires Access 2000 or later.)
 
E

Ed Bloom

Thank you.

Allen Browne said:
Something like this:

Dim lngI as Long
Dim strDoc As String
Const strcSwitchboard = "Switchboard"

For lngI = Forms.Count -1 To 0
strDoc = If Forms(lngI).Name
If strDoc <> strcSwitchboard Then
DoCmd.Close acForm, strDoc
End If
Next

If Not CurrentProject.AllForms(strcSwitchboard).IsLoaded Then
DoCmd.OpenForm strcSwitchboard
End If

(The last part requires Access 2000 or later.)
 
J

Jezzepi

To open the switchboard when all other forms are closed simply do the
following:

if(forms.count<1) then docmd.open "MySwitchboardForm"
 

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