Karen Schaefer
asked on
use ctl.tag to hide controls on active form/subforms.
Need help with the following code:
I set the tag = "HC" (Hide controls) for multiple fields on main form and also on controls of page(tabs). for some reason the current code will hide the pages when I name the control specifically and not with the ctl.tag.
I also need to modify code to be able to hide controls on a subform.
Please help,
K
I set the tag = "HC" (Hide controls) for multiple fields on main form and also on controls of page(tabs). for some reason the current code will hide the pages when I name the control specifically and not with the ctl.tag.
I also need to modify code to be able to hide controls on a subform.
Please help,
K
Private Sub HideMultiUnitflds()
Dim ctl As Control
Dim nfrmSub As SubForm
Dim nMU As Boolean
nMU = Me.MultiUnit.Value
If nMU = True Then
For Each ctl In Me.Controls
If ctl.Tag = "HC" Then
' Debug.Print ctl.Name
' If ctl.Visible = True Then
Me.pg_RentComps.Visible = False
Me.pg_SubjUnits.Visible = False
Me.txtValuePerUnit.Visible = False
Me.txtUnits.Visible = False
ctl.Visible = False
'Else
Me.pg_RentComps.Visible = True
Me.pg_SubjUnits.Visible = True
ctl.Visible = True
'End If
End If
Next
End If
End Sub
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Here is my final code.
Private Sub HideMultiUnitflds()
Dim ctl As Control
Dim nMU As Boolean
Dim stag As String
' certain fields are to be visible only if multi-unit is checked
' is multi-unit checked?
nMU = Nz(Me.MultiUnit.Value, False)
For Each ctl In Me.Controls
stag = ctl.Tag
If stag = "HC" Then
ctl.Visible = nMU
End If
Next
Me.frm_SalesComps_sub.Form
For Each ctl In Me.frm_SalesComps_sub.Form
stag = ctl.Tag
If stag = "HCSub" Then
ctl.Visible = nMU
End If
Next
End Sub