Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Closing all forms before exiting to Main Form / Switchboard 1

Status
Not open for further replies.

zevw

MIS
Jul 3, 2001
697
US
When I click on the "X" of access it activates the Form_Unload event procedure from the main form. I want to close all forms that are open before I exit the program with the following code.

Code:
        For Each frm In Forms
            frmName = frm.Name
            If frmName <> "Main" Then
                DoCmd.Close acForm, frmName
            End If
        Next frm

What I find happening is that if I have more than one form open, it will close all the forms and leave one form open excluding the Main form that is conditionally not closed. What can I do to make sure that all forms close, and why does it according to my code leave one form open.

I also saw something on Isloaded but I do not know how to write it.

I will appreciate any help on this matter and thank you in advance for your help.


 
For i = Forms.Count - 1 To 0 Step -1
frmName = Forms(i).Name
If frmName <> "Main" Then
DoCmd.Close acForm, frmName
End If
Next

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 
Is it possible to do the for reports. To close all the reports before exiting?
 
Is it possible to do the for reports
Why not trying ?
 
Thanks!

It works fine.

Is it possible to do the same for reports

I appreciate when people point out my mistakes.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top