Results 1 to 13 of 13
  1. #1
    dkeeper09 is offline Novice
    Windows XP Access 2007
    Join Date
    Oct 2011
    Posts
    15

    Close subforms

    Hey guys.



    I have a form with a few buttons on it. The buttons open and close the respective subforms. I only have on issue.
    Lets say I click button A to open subform A. Then I decide I want to click button B to open subform B. Is there a way to get subform A to close when I open subform B? Right now, I have to physically close subform A before I open subform B or it gets in the way.
    Hope it makes sense
    Any help is greatly appreciated. Thank you.

  2. #2
    dkeeper09 is offline Novice
    Windows XP Access 2007
    Join Date
    Oct 2011
    Posts
    15
    Right now, I have this for the button code:

    Private Sub AddDeleteAssetCategories_Click()
    Me![Assets].Visible = Not Me![Assets].Visible
    End Sub

  3. #3
    hertfordkc is offline 18 year novice
    Windows XP Access 2007
    Join Date
    Mar 2011
    Posts
    481
    Have you tried tying macros to each button, where one macro Opens Form A, closes Form B and the other macro Opens Form B, closes Form A?
    You may have to alter a setting to suppress any error message that might arise if the form being closed isn't open.

  4. #4
    dkeeper09 is offline Novice
    Windows XP Access 2007
    Join Date
    Oct 2011
    Posts
    15
    Do you know what the macro code would be for closing the form?

  5. #5
    hertfordkc is offline 18 year novice
    Windows XP Access 2007
    Join Date
    Mar 2011
    Posts
    481
    Quote Originally Posted by dkeeper09 View Post
    Right now, I have this for the button code:

    Private Sub AddDeleteAssetCategories_Click()
    Me![Assets].Visible = Not Me![Assets].Visible
    End Sub
    That code doesn't close a form, it just makes it invisible.
    If you mean to close assets on this click, in place of
    Me![Assets].Visible = Not Me![Assets].Visible
    you need something like
    Docmd.Close acForm,"Assets",acSaveNo

  6. #6
    dkeeper09 is offline Novice
    Windows XP Access 2007
    Join Date
    Oct 2011
    Posts
    15
    Hmm. Ok, well lets say I just stick with the Invisible/visible code. Is there a way to make the other forms invisible when I make a form visible?

  7. #7
    orange's Avatar
    orange is online now Moderator
    Windows XP Access 2003
    Join Date
    Sep 2009
    Location
    Ottawa, Ontario, Canada; West Palm Beach FL
    Posts
    16,744
    Can you tell us what you want to happen and when?

    If I click button A, then I want .....

  8. #8
    dkeeper09 is offline Novice
    Windows XP Access 2007
    Join Date
    Oct 2011
    Posts
    15
    if i click button a, make sure subforms b and c are invisible, open subform a.

    if i click button b, make sure subforms a and c are invisible, open subform b.

  9. #9
    boblarson is offline --------
    Windows 7 64bit Access 2010 32bit
    Join Date
    Jun 2011
    Posts
    1,272
    Just a learning moment - You are using the term SUBFORM incorrectly. A Subform is a form that is displayed ON a parent form by use of a subform control (control which houses the subform on the parent form). It does NOT refer to a completely separate form which can be opened and closed.

    So, from what I'm seeing, you are NOT using subforms, but are just using different forms for different parts of your entry and editing.

    This is important to note since it makes a BIG difference when you are asking a question.

  10. #10
    hertfordkc is offline 18 year novice
    Windows XP Access 2007
    Join Date
    Mar 2011
    Posts
    481

    See my markup of your last message.

    Quote Originally Posted by dkeeper09 View Post
    if i click button a, make sure subforms b and c are invisible, open subform a.
    Forms![B].visible = no
    Forms![C].visible = no
    Docmd.Opernform "A", parameters


    if i click button b, make sure subforms a and c are invisible, open subform b.
    Forms![A].visible = no
    Forms![C].visible = no
    Docmd.Opernform "B", parameters


    Two more notes: If you are not certain of the state of the other forms, you will need to set up error trapping so your process reaches the desired end.
    Second, I'm doing this without my Access computer, so the syntax hasn't be checked. if you get errors, try help on the lines on which you get errors. I'll be here if you get stuck.

  11. #11
    boblarson is offline --------
    Windows 7 64bit Access 2010 32bit
    Join Date
    Jun 2011
    Posts
    1,272
    Quote Originally Posted by hertfordkc View Post
    Forms![A].visible = no
    Forms![C].visible = no
    Docmd.Opernform "B", parameters
    A bit off (but understandable if you don't have something to test with).

    Forms!A.Visible = FALSE
    Forms!C.Visible = FALSE
    DoCmd.OpenForm "B", acNormal


    but a simpler way is to create a function:

    Code:
    Function OpenForm(strFormNameHere)
        Dim frm As Form
        For Each frm in CurrentProject.AllForms
             If frm.Name = strFormNameHere Then
                If CurrentProject.AllForms(frm.Name).IsLoaded = False Then
                   DoCmd.OpenForm frm.Name, acNormal
                Else
                   frm.Visible = True
                End If
              Else
                 frm.Visible = False
              End If
        Next
    End Function
    Then just call your function from the button's click event and pass the appropriate form name you want to be displayed.

    In Button A you would use

    Code:
    OpenForm "A"
    or for Button B
    Code:
    OpenForm "B"
    Which would open the form designated and hide all others.

  12. #12
    dkeeper09 is offline Novice
    Windows XP Access 2007
    Join Date
    Oct 2011
    Posts
    15
    Sorry for the late response.

    So I add that function to each button right, and just change the form names to the correct ones?

  13. #13
    boblarson is offline --------
    Windows 7 64bit Access 2010 32bit
    Join Date
    Jun 2011
    Posts
    1,272
    Quote Originally Posted by dkeeper09 View Post
    Sorry for the late response.

    So I add that function to each button right, and just change the form names to the correct ones?
    No, you don't add that function to each button. You only ADD IT ONCE to a Standard Module and then you can CALL the function from the button click events.

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Replies: 2
    Last Post: 06-20-2011, 03:10 PM
  2. Close on date
    By JSHEL in forum Programming
    Replies: 5
    Last Post: 12-22-2010, 04:42 PM
  3. Add a close button?
    By thestappa in forum Reports
    Replies: 1
    Last Post: 07-15-2010, 10:43 AM
  4. Close All but One Form
    By Bruce in forum Forms
    Replies: 4
    Last Post: 04-06-2010, 09:31 AM
  5. Close DAP Connection
    By gfultz in forum Access
    Replies: 0
    Last Post: 10-16-2009, 10:11 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums