Results 1 to 6 of 6
  1. #1
    Platinum Lounger
    Join Date
    Dec 2001
    Location
    Melbourne, Australia
    Posts
    4,594
    Thanks
    0
    Thanked 27 Times in 27 Posts

    Closing all Open forms except Main Menu (Access 2000)

    Has anybody got some code to Close all open forms except the Main Menu form. I wish to run this code from the Main Menu from in the OnOpen event.

  2. #2
    Gold Lounger
    Join Date
    Feb 2001
    Location
    Sint Niklaas, Belgium
    Posts
    2,778
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Closing all Open forms except Main Menu (Access 2000)

    You can use this code :<pre>Function CloseForms()
    Dim frm As Form
    For Each frm In Forms
    If frm.Name <> "Main Menu" Then
    DoCmd.Close acForm, frm.Name
    End If
    Next frm
    End Function</pre>

    Replace Main Menu with the name of your main menu form.
    Francois

  3. #3
    Platinum Lounger
    Join Date
    Dec 2001
    Location
    Melbourne, Australia
    Posts
    4,594
    Thanks
    0
    Thanked 27 Times in 27 Posts

    Re: Closing all Open forms except Main Menu (Access 2000)

    Thanks Francois
    Does the Forms collection contain all loaded forms as opposed to all forms.
    When would you use the AllForms collection?

  4. #4
    Gold Lounger
    Join Date
    Feb 2001
    Location
    Sint Niklaas, Belgium
    Posts
    2,778
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Closing all Open forms except Main Menu (Access 2000)

    So far I understand the difference :
    Forms contains all open forms (not subforms)
    AllForms contains all the forms in the database.
    If I'm wrong, can someone correct me ?
    Francois

  5. #5
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Closing all Open forms except Main Menu (Access 2000)

    That is correct.

    The Forms collection can be used to refer to an open (main) form, or to loop through all open forms, as in the code example you posted for Pat.

    The AllForms collection can be used to loop through all forms in the database, whether open or not; an alternative is to use the DAO Forms container and loop through its Documents collection.

    Similarly, the Reports collection contains all open reports (not subreports), and the AllReports collection contains all reports defined in the database.

  6. #6
    Gold Lounger
    Join Date
    Feb 2001
    Location
    Sint Niklaas, Belgium
    Posts
    2,778
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Closing all Open forms except Main Menu (Access 2000)

    Thanks to confirm my thoughts.
    Francois

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •