DZone Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world

Snippets has posted 5883 posts at DZone. View Full User Profile

Close All Forms In Access

04.26.2007
| 9576 views |
  • submit to reddit
        Sometimes, it's necessary to close all forms in a single procedure:

Function CloseAllForms()

'It will close all forms before opening the new form (if required)

Dim obj As Object
Dim strName As String

For Each obj In Application.CurrentProject.AllForms
DoCmd.Close acForm, obj.name, acSaveYes
Next obj

End Function

Close all forms - except one particular screen:


Function CloseAllForms()


Dim obj As Object
Dim strName As String

For Each obj In Application.CurrentProject.AllForms

If obj.Name <> "Your Form" Then 

DoCmd.Close acForm, obj.name, acSaveYes

End if 
Next obj

End Function