• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 422
  • Last Modified:

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
    Else
        Me.Form![Edit Camera Listing].Visible = False
    End If
    
Exit_cmdcamera_Click:
    Exit Sub
 
Err_cmdcamera_Click:
    MsgBox Err.Description
    Resume Exit_cmdcamera_Click
    
End Sub

Open in new window

0
JamieBennett
Asked:
JamieBennett
1 Solution
 
peter57rCommented:
"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:
me.containercontrolname.Form!controlname

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.

Like..

Me.containercontrolname.SetFocus
Me.containercontrolname.Form!controlname.SetFocus
0
 
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.
0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now