Tip: Leave Me Open

You often want to give your users the ability to close all of the open forms in an application. Here’s a version of the code that closes all of the forms—except the form that routine is called from:

Function CloseAllButMeForms(frm As Form) As Boolean



On Error Goto AtEnd 
Dim i As Integer 

For i = Forms.Count - 1 To 0 Step -1     

  If frm.Name <> Forms(i).Name Then         
    DoCmd.Close acForm, Forms(i).Name     
  End If 

Next i


AtEnd:



  CloseAllButMeForms = (Forms.Count <= 1) 

End Function

 

 

This entry was posted in Forms. Bookmark the permalink.

Leave a Reply

Your email address will not be published.


*


This site uses Akismet to reduce spam. Learn how your comment data is processed.