Set the On Close property of each form to:
=Keep1Open([Form])
and each report to:
=Keep1Open([Report])
Then if no forms or reports are visible, it will open the switchboard again.
Public Function Keep1Open(objMe As Object)
On Error GoTo Err_Keep1Open
'Purpose: Open the Switchboard if nothing else is visible.
'Argument: The object being closed.
'Return: None.
'Usage: In the OnClose property of forms and reports:
' =Keep1Open([Form])
' =Keep1Open([Report])
Dim sName As String 'Name of the object being closed.
Dim lngObjType As Long 'acForm or acReport
Dim bFound As Boolean 'Flag not to open the switchboard.
Dim frm As Form 'an open form.
Dim rpt As Report 'an open report.
'Initialize
sName = objMe.Name
If TypeOf objMe Is Form Then
lngObjType = acForm
ElseIf TypeOf objMe Is Report Then
lngObjType = acReport
End If
'Any other visible forms?
For Each frm In Forms
If frm.Visible Then
If frm.Name <> sName Or lngObjType <> acForm Then
bFound = True
Exit For
End If
End If
Next
'Any other visible reports?
If Not bFound Then
For Each rpt In Reports
If rpt.Visible Then
If rpt.Name <> sName Or lngObjType <> acReport Then
bFound = True
Exit For
End If
End If
Next
End If
'If none found, open the switchboard.
If Not bFound Then
DoCmd.OpenForm "Switchboard"
End If
Exit_Keep1Open:
Set frm = Nothing
Set rpt = Nothing
Exit Function
Err_Keep1Open:
If Err.Number <> 2046& Then 'OpenForm is not available when closing
database.
Call LogError(Err.Number, Err.Description, conMod & ".Keep1Open()")
End If
Resume Exit_Keep1Open
End Function
--
Allen Browne - Microsoft MVP. Perth, Western Australia.
Reply to group, rather than allenbrowne at mvps dot org.
I have an Access app that I plan to convert to an mde file for users to
run without Access loaded. I have a Switchboard for the Main Menu. Is
there a global method to have the Switchboard be open if no other forms
are open. I have so many forms and I do a lot of opening and closing of
forms in code, sometimes in Normal view and sometimes in Design view.
So I was hoping to not have to embed logic all throughout my code to
get the Menu to be available when no other forms are loaded.
Thanks for any suggestions.