Close all items (1 Viewer)

hardik_088

Registered User.
Local time
Today, 15:28
Joined
May 31, 2011
Messages
82
hello dear,
I have log out button and when i clicked on that then login form will open and another all items will close like table,forms etc... and I have close all forms and table manually in macro. but is there a any ways that i can close all itmes ?

Thanks
 

hardik_088

Registered User.
Local time
Today, 15:28
Joined
May 31, 2011
Messages
82
hi BobMcClellan
i am trying to close all forms but i don't know how it is working.sometime it is closing 1 form ,sometime is closing 3 forms and sometime it close itself and other forms are still open. what that?

Code is here.

Private Sub Command0_Click()
'Close all open forms
Dim frm As Form
For Each frm In Forms
DoCmd.Close acForm, frm.Name
Next

End Sub

Thanks a lot
 

boblarson

Smeghead
Local time
Today, 15:28
Joined
Jan 12, 2001
Messages
32,059
To close all open forms you would use this (it has to be in reverse order or else the index gets off and you will likely want to keep the one login form open):

Code:
Function CloseOpenFrms()    
    Dim z As Integer
 
    For z = Forms.Count-1 0 Step -1
        If Forms(z).Name <> "[B][COLOR=red]YourLoginFormNameHere[/COLOR][/B]" Then
           DoCmd.Close acForm, Forms(z).Name, acSaveNo
        End If
    Next z
End Function
 
Last edited:

hardik_088

Registered User.
Local time
Today, 15:28
Joined
May 31, 2011
Messages
82
thanks dear,
but sorry there one small mistake but i am new totaly so i could not solve here

Error : next without For

Dim z As Integer

For z = Forms.Count - 1 To 0 Step -1
If Forms(z).Name <> "YourLoginFormNameHere" Then
DoCmd.Close acForm, Forms(z).Name, acSaveNo
Next
 

hardik_088

Registered User.
Local time
Today, 15:28
Joined
May 31, 2011
Messages
82
hi dear
i want to do something more like if I want to close all forms accept two forms so waht i should do?

Thanks a lot
 

Users who are viewing this thread

Top Bottom