Grouping of controls

E

Enzo Diana

On a form I have many controls which will be either visible, invisible or
change colours depending on the value selected from a combo box.
Is there a way to "group" controls so I don't have to refer to each one
specifically to change their visibilty and colour. Thanks in anticipation
 
W

Wayne Morgan

Probably the easiest way is to name them with sequential numbers.

Example:
txtTextbox1
txtTextbox2
txtTextbox3

You can then use a For...Next loop to refer to them

Dim i as Byte
For i = 1 To 3
Me.Controls("txtTextbox" & i).BackColor = 0
Next i
 
D

Douglas J. Steele

In addition to Wayne's suggestion, if you have a situation where you have a
disparate group of controls that you need to toggle (some text boxes, labels
and checkboxes, for example), assign a common Tag property value for the
group (you can do this in a single step by select all of the controls in the
group and then setting the Tag property for all of the selected controls).
You can then loop through all controls on the form, checking the Tag
property and setting the Visible property as appropriate.

Sub ToggleControls(GroupName As String, Visibility As Boolean)

Dim ctlCurr As Control

For Each ctlCurr In Me.Controls
If ctlCurr.Tag = GroupName
ctlCurr.Visible = VIsibility
End If
Next ctlCurr

End Sub
 
L

Larry

You can possibly use the Tag property on these controls to
group similar controls together. By doing so , you can
loop through all your controls and set the visible
property, for example, based on the tag value.
 
E

Enzo Diana

Thanks Wayne and Doug. I used a variation of the Tag idea from Doug and have
it working well. Thanks to you both
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top