Referencing labels in a FOR loop

retro

Registered User.
Local time
Today, 23:06
Joined
Sep 5, 2003
Messages
69
I want to be able to do something to several labels, e.g. make them invisible, using a FOR loop. They are all named similarly, with ascending numbers on the end, e.g. lblName20

Say I want to make lblName20 to lblName40 invisible. I need something along the lines of:

Code:
            Dim labelname As String
            For c = 20 To 40
                labelname = "lblName" & c
                labelname.Visible = False
            Next c

Of course, that doesn't work, because it doesn't recognize the string as a label name. I'm sure there must be something simple I'm overlooking - unfortunately, my VBA is very rusty!

How do I go about this?
 
Try

Me(labelname).Visible
 
Brilliant! I knew I was missing something simple. Many thanks! :)
 

Users who are viewing this thread

Back
Top Bottom