PDA

View Full Version : Multiple Controls on a Form



Kenw
09-16-2015, 12:50 PM
I have a matrix of 4 x 3 combo boxes on a form and wish to perform the same action on each of the 12 (ie make visible, set font, set list index get input etc etc etc) Do I have to write routines specific to each control or can I build up commands by stringing the various parts of the box address into a variable and obeying that variable.
I have tried the latter but it doesn't seem to work (eg com = "t"&t&"c"&c&".visible = false" to hide a control - the content of com looks OK but how do I get Excel to perform it.
Any ideas or suggestions would be welcome.

p45cal
09-16-2015, 01:00 PM
You should be able to do something along these lines:
For i = 1 To 12
Controls("Combobox" & i).BackColor = &H80000002
Next i

Kenw
09-16-2015, 02:10 PM
Thanks a million - seems to do what I need - easy when you know how and you obviously know how - thanks again

Paul_Hossler
09-16-2015, 03:12 PM
I like to give UF controls a meaningful name instead of Combobox1, etc. i.e cboxJan, cboxFeb, etc.

If there's different kinds then the .Tag property can provide finer control





Option Explicit

Private Sub UserForm_Initialize()
Dim oControl As Control

For Each oControl In Me.Controls
If TypeOf oControl Is ComboBox And oControl.Tag = "MONTH" Then
oControl.BackColor = &H80000002
End If
Next
End Sub