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 TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Is there a generic way of closing opened forms and reports 1

Status
Not open for further replies.

SkyHigh

Technical User
May 30, 2002
309
CA
Hi Folka
Is there a way I can close all opened forms and reports using one command button.

Thanks
Brenda
 
Application.Quit will do it, for sure.

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ222-2244
 
Well thats what I don't want to do, there is a logout option required in my application so once this option is selected all the opened objects should close and the login form should open.

Thanks
 
Something like this ?
For Each rpt In Application.Reports
DoCmd.Close acReport, rpt.Name
Next rpt
For Each frm In Application.Forms
If frm.Name <> Me.Name Then
DoCmd.Close acForm, frm.Name
End If
Next frm

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ222-2244
 
I think the best way would be to first get the names of all the forms and reports into an array and then loop them through a function to see if they are opened if so then close them.

Can someone pls help me with the code.

Thanks
Brenda
 
Brenda,

You dont need an array as Access already handles the forms and reports collections. Use this code. It works.

Code:
For int1 = 0 To CurrentProject.AllForms.Count - 1
    If CurrentProject.AllForms.Item(int1).IsLoaded = True Then
        DoCmd.Close acForm, CurrentProject.AllForms.Item(int1).NAME
    End If
Next int1

You can use the same code for reports, just replace the any instance of 'forms' with 'reports'.

Phil Edwards
 
Great dude !! works like a charm.
Thanks ever so much !!
Have a star
Brenda
 
Brenda, just to know, doesn't my code works ?
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top