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 On Userforms (2000)

    I have a userform on which are placed several labels. The labels are named:
    lbl1, lbl2, lbl3 etc. I want to generate a random number and use that number to select the label and change its background colour.
    Eg, random number 6 then lbl6 is referenced.
    I've done this before, I'm sure, but the syntax for referencing the label with a variable eludes me.
    Any takers?

    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 On Userforms (2000)

    Let's say that you have a variable intLabelNo. You can use code similar to this:

    intLabelNo = Int(10 * Rnd + 1)
    Me.Controls("lbl" & intLabelNo).BackColor = vbRed

  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 On Userforms (2000)

    Many thanks, Hans.
    <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
  •