-
SOLVED - Using variable in property names
Guys,
I am sure there must be a relatively simple anwer to this, but I am stumped at locating the resolution... please 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'
[vba]
for x = 1 to 12
LabelName = "Tag" & x
strBoxNm = "Box" & x
LabelName.value = strBoxNm
next x
[/vba]
Hopefully this is a relatively straightforward query.
thanks in advance.
Last edited by Remalay; 12-03-2008 at 05:56 AM.
Reason: SOLVED
-
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
-
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
-
RESOLVED - Using variable in property names
Thanks nemmi69 for your input. It successfully guided me to the answer needed:
[VBA]
For x = 1 To 12
Label = "lbl" & x
frmData.Controls(Label).Caption = vaDataSet(1, x)
Next x
[/VBA]
Thanks agiain.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules