Control Arrays or Object Naming

  • Thread starter Thread starter Ed Brala
  • Start date Start date
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
 
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?
 
Back
Top