Check and Close All Forms Except Switchboard

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

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.
 
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.)
 
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.)
 
To open the switchboard when all other forms are closed simply do the
following:

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