Hello,
I have a form which includes an option group and multiple controls that I would like to hide if a user selects a certain option in the option group.
The option box is called fmeKnitWovenOther. There is a label called fmeKnitWovenOtherLbl that I would like to hide when any option is selected and a number of controls I would like to hide only if the user selects option 2. I have this so far and it works OK:
Private Sub fmeKnitWovenOther_AfterUpdate()
If Me.fmeKnitWovenOther = 1 Then
Me.fmeKnitWovenOtherLbl.Visible = False
ElseIf Me.fmeKnitWovenOther = 2 Then
Me.fmeKnitWovenOtherLbl.Visible = False
Me.txtThreadsWarp.Visible = False
Me.txtThreadsWarpLbl.Visible = False
Me.cmbThreadsWarpUOM.Visible = False
Me.txtThreadsWeft.Visible = False
Me.txtThreadsWeftLbl.Visible = False
Me.cmbThreadsWeftUOM.Visible = False
Me.fmeCombedOrCarded.Visible = False
Me.txtYarnSizeWarp.Visible = False
Me.txtYarnSizeWarpLbl.Visible = False
Me.cmbWarpYarnUOM.Visible = False
Me.txtYarnSizeWeft.Visible = False
Me.txtYarnSizeWeftLbl.Visible = False
Me.cmbWeftYarnUOM.Visible = False
Me.txtFabricWeight.Visible = False
Me.txtFabricWeightLbl.Visible = False
Me.cmbFabricWeightUOM.Visible = False
ElseIf Me.fmeKnitWovenOther = 3 Then
Me.fmeKnitWovenOtherLbl.Visible = False
Else
Me.fmeKnitWovenOtherLbl.Visible = True
End If
End Sub
The problem is that I have set the .visible property of every control individually, but I will need to expand this form and add more controls to be hidden for the other two options. If I keep setting the .visible property for every control manually, I am going to wind up with a giant list of controls all manually set to .visible = True and .visible = False depending on the If or ElseIf condition.
It seems like there has to be a better way. Does anyone know if it is possible to create a collection, array, or enumeration of each group of controls and then set the .visible property of just that collection for each If / ElseIf condition? Or is there just some other way to achieve this more neatly?
Please let me know any thoughts you have.
Thank you very much in advance for any help you can offer.