Link to home
Start Free TrialLog in
Avatar of Karen Schaefer
Karen SchaeferFlag for United States of America

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

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

Open in new window

SOLUTION
Avatar of IrogSinta
IrogSinta
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Karen Schaefer

ASKER

thanks.

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.CompNotes.SetFocus
   
    For Each ctl In Me.frm_SalesComps_sub.Form.Controls
        stag = ctl.Tag
        If stag = "HCSub" Then
            ctl.Visible = nMU
        End If
    Next
End Sub