Show/Hide multiple subforms on click of a command button

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

Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

"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.



Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
JamieBennettAuthor Commented:
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.
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft Access

From novice to tech pro — start learning today.