Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

toggle visible property for a subform 2

Status
Not open for further replies.

mmaddox

IS-IT--Management
May 22, 2002
53
US
I have a form with a subform. I want the subform to not be visible unless a command button is clicked, which sets the visible property to true and the subform displays. I can set the property in design view, but what is the coding to toggle with a command button?

This does not work:

Private Sub Command56_Click()
frm_software.Visible = True
End Sub

Any help would be appreciated
 
Try the following:

Code:
    Me!subformcontrol.Visible = True

where
Code:
subformcontrol
is the name of the subform control [NOT the name of the subform it points to in the Database window].
Jim Kraxberger
Developing Access solutions since 1995
 
Try this behind your Button.

If Me!SubFormName.Form!ControlName.Visible = True Then
Me!SubFormName.Form!ControlName.Visible = False
Else
Me!SubFormName.Form!ControlName.Visible = True
End if

Change SubFormName and ControlName to your own.

 
Sorry kraxmo we must have posted simultaneously. I read toggle to mean on/off, in the above example I forgot to set the focus to another control before attempting to hide it.

If Me!SubFormName.Form!ControlName.Visible = True Then
Me!SubFormName.Form!AnotherControlName.Setfocus
Me!SubFormName.Form!ControlName.Visible = False
Else
Me!SubFormName.Form!ControlName.Visible = True
End if
 
billpower is correct!!! You must switch the focus from the subform to some other control prior to making the subform invisible. Jim Kraxberger
Developing Access solutions since 1995
 
I am following this example in an app I am building where a button in one of two subforms that is located on a tabbed form. It is to be tasked with the ability to set the visibility of this subform to false. I have the following code in the click property of the button:
Forms!masterForm!secondSubform1!thirdSubform!fieldName.SetFocus
Forms!masterForm!secondSubform2.Visible = False

It appears that the setFocus command is operating correctly, but the visible command pops up an error that 'You cannot hide a control that has the focus'; even after setting the setFocus to another subForm field. Am I doing something incorrectly?
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top