Show/Hide multiple subforms on click of a command button

Posted on 2008-11-15
Last Modified: 2013-11-28
I have searched the questions out on this site and still having a problem with doing two actions and an else from a command button. Main form will have about 10 subforms, with 10 command buttons on the left side of main form. Once a button is clicked on I am trying to make that particular form visible and set the focus to a certain field on the subform. Also, in the script I am trying to make the subform not visible if it is not click or have the focus. Here is what my script looks like now. I have tried different things and am confussing myself more.

Private Sub cmdcamera_Click()

On Error GoTo Err_cmdcamera_Click


    If Me.cmdcamera = True Then

'        Me.fCameraInfo.Visible = True

        Me.Form![Edit Camera Listing] = True

        Me.Form![Edit Camera Listing].SetFocus

        Me.Form![Edit Camera Listing]!CAMID.SetFocus


        Me.Form![Edit Camera Listing].Visible = False

    End If



    Exit Sub


    MsgBox Err.Description

    Resume Exit_cmdcamera_Click


End Sub

Open in new window

Question by:JamieBennett
    LVL 77

    Accepted Solution

    "If Me.cmdcamera = True Then"
    Are you using toggle buttons rather than command buttons?

    The main issue here is the syntax for referring to subforms and controls on subforms.

    On the main form, each subform is held inside a container control which is a 'subform control'.
    The container control has a name which is independent of the form it contains, although it is usually the same as the subform, because of the way Access names controls. Depending on how the subform is added though, you can get names like Child1, Child2 etc..  Technically, you always use the name of the container control and you never use the name of the subform, in referring to the subform or it's controls.
    You can see the name of the container controls in design view of the main form, by dropping down the object list which is the first dropdown on the formatting toolbar.

    In code on the main form, to make the subform container control visible you would use:
    me.containercontrolname.visible = true

    To refer to a control on the subform, you use:

    However to set the focus to a control on a subform, you first have to set the focus to the container control, and then set focus to the subform control.



    Author Comment

    I am using command buttons and can get them to work separetly, but when I try to combine what I am wanting to achieve it tells me the method is not supported. Going to work on this this afternoon. I just tried the toggle button and that does not work either. Will revise the form and try the toggle buttons again. I have used command buttons before and tabs. I was tring to acheive a form of showing or hiding a form in a main form in a small area of the main form.

    Featured Post

    Gigs: Get Your Project Delivered by an Expert

    Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

    Join & Write a Comment

    This article is a continuation or rather an extension from Cascading Combos ( and builds on examples developed in detail there. It should be understandable alone, but I recommend reading the previous artic…
    In the article entitled Working with Objects – Part 1 (, you learned the basics of working with objects, properties, methods, and events. In Work…
    Familiarize people with the process of utilizing SQL Server functions from within Microsoft Access. Microsoft Access is a very powerful client/server development tool. One of the SQL Server objects that you can interact with from within Microsoft Ac…
    Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…

    754 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    24 Experts available now in Live!

    Get 1:1 Help Now