Results 1 to 3 of 3
  1. #1
    4 Star Lounger
    Join Date
    Sep 2002
    Location
    Stafford, Staffordshire, England
    Posts
    585
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Labels in Code (xp)

    I have some labels named Label1through Label20 on a userform. Is there a way to refer to these labels dynamically from within code using a variable? For example, if the variable is X=2, say, I want to change the BackColor property of Label2 to a different value.

    TIA
    <font color=blue><font face="Script MT Bold"><big>Rob</big></font face=script></font color=blue>

  2. #2
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Labels in Code (xp)

    Yes, you can use

    Me.Controls("Label" & X).BackColor = vbGreen

    if the code is in the userform module, or

    UserForm1.Controls("Label" & X).BackColor = vbMagenta

    where UserForm1 is the name of the form.

  3. #3
    4 Star Lounger
    Join Date
    Sep 2002
    Location
    Stafford, Staffordshire, England
    Posts
    585
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Labels in Code (xp)

    Thanks Hans. You are a star!
    <font color=blue><font face="Script MT Bold"><big>Rob</big></font face=script></font color=blue>

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •