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

Microsoft Access

Avatar of undefined
Last Comment
Karen Schaefer
SOLUTION
Avatar of IrogSinta
IrogSinta
Flag of United States of America image

Blurred text
THIS SOLUTION IS ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
ASKER CERTIFIED SOLUTION
THIS SOLUTION IS ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
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
Microsoft Access
Microsoft Access

Microsoft Access is a rapid application development (RAD) relational database tool. Access can be used for both desktop and web-based applications, and uses VBA (Visual Basic for Applications) as its coding language.

226K
Questions
--
Followers
--
Top Experts
Get a personalized solution from industry experts
Ask the experts
Read over 600 more reviews

TRUSTED BY

IBM logoIntel logoMicrosoft logoUbisoft logoSAP logo
Qualcomm logoCitrix Systems logoWorkday logoErnst & Young logo
High performer badgeUsers love us badge
LinkedIn logoFacebook logoX logoInstagram logoTikTok logoYouTube logo