Control Arrays or Object Naming

E

Ed Brala

I have a form with multiple labels.I named each
one "lbl1","lbl2" ....
i want to be able to loop through these and change the
captions. I know in VB you can create control arrays and
just loop. But I don't see that in VBA. Is it possible to
assign an object? When I write the following code I get an
error. Help

Dim MyControl as Object
Dim x as integer

For x = 1 to 10
set MyControl = "lbl"&x
MyControl.Caption = """"
Next x
 
W

Wayne Morgan

VBA doesn't do control arrays, but you're on the right track. Try changing
set MyControl = "lbl"&x
to
Set MyControl = Me.Controls("lbl" & x)

You could also skip this line and use

Me.Controls("lbl" & x).Caption = """"

I believe that using 4 quote marks will leave a double quote in the caption,
not clear the caption. Is that your intent?
 

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