Closing all forms at once

  • Thread starter Thread starter Grace Marquis
  • Start date Start date
G

Grace Marquis

I need to create code to place behind a command button in
the toolbar to go back to the main menu. It should close
all open forms except for the main menu. I know it must
be simple to do, but I have not found any code in any
books or knowledge base. I've got it to somewhat work, but
I can't get it to close the popup forms.

Appreciate any help.

Thanks...Grace
 
Loop backwards through the Forms collection.

The basic idea is this:

Function CloseAllForms()
Dim lng As Long
Dim strName As String

For lng = Forms.Count - 1 To 0 Step -1
strName = Forms(lng).Name
If strName <> "frmSwitchboard" Then
DoCmd.Close acForm, strName
End If
Next
End Function


That should work with popup forms. There is a bug with the Close action,
where it silently loses your entry if the record is dirty and there is any
reason why it cannot be saved (e.g. required field missing, validation rule
not met, duplicate index, related record required, ...).
 
Back
Top