PDA

View Full Version : Using variable in property names



Remalay
12-03-2008, 04:20 AM
Guys,
I am sure there must be a relatively simple anwer to this, but I am stumped at locating the resolution... please HELP! :help


I just want to use an incrementing variable to address a series of properties on a userform. E.g. a series of labels numbered from 'Tag1' to 'Tag12'



for x = 1 to 12
LabelName = "Tag" & x
strBoxNm = "Box" & x
LabelName.value = strBoxNm
next x


Hopefully this is a relatively straightforward query.

thanks in advance.

nemmi69
12-03-2008, 05:36 AM
Hope this helps

Dim Ctrl As Control

Sub ChangeLabelsTo8()
For Each Ctrl In UserForm1.Controls
If Left(Ctrl.Name, 5) = "Label" Then Ctrl.Caption = "8"
Next
End Sub

nemmi69
12-03-2008, 05:40 AM
Oops sorry, you wanted it to accept variables

Dim Ctrl As Control
Dim Anum As Single

Sub ChangeLabelsTo8()
Anum = 4
For Each Ctrl In UserForm1.Controls
If Left(Ctrl.Name, 5) = "Label" Then Ctrl.Caption = Anum
Anum = (Anum * Anum) - Anum
Next
End Sub

Remalay
12-03-2008, 05:54 AM
Thanks nemmi69 for your input. :clap: It successfully guided me to the answer needed:


For x = 1 To 12
Label = "lbl" & x
frmData.Controls(Label).Caption = vaDataSet(1, x)
Next x


Thanks agiain.