Tip: Leave Me Open

<< Click to Display Table of Contents >>

Navigation:  Forms  >

Tip: Leave Me Open

Steven Backman        

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



 CloseAllButMeForms = (Forms.Count <= 1)
End Function