Results 1 to 4 of 4
  1. #1
    2 Star Lounger
    Join Date
    Nov 2001
    Posts
    119
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Can I tag a variable value onto a label name? (Word 2002)

    Hi,

    I have 10 labels, named in sequence, Label1, Label2, Label3 etc...

    I need to be able to access the label name in code using a variable value for 1,2,3 etc. I am attempting to use the following method, but it doesn't work:

    Sub ChangeLabelCaption(ByVal i as Integer)
    With Label & i
    .Caption = "Does Not Work"
    End With
    End Sub

    Any ideas?

    Thanks!

    Chris

  2. #2
    5 Star Lounger
    Join Date
    Jul 2002
    Location
    Toronto, Ontario, Canada
    Posts
    1,139
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Can I tag a variable value onto a label name? (Word 2002)

    Change the With Label & i

    to

    With Me.Controls("Label" & CStr(i))
    --
    Bryan Carbonnell - Toronto <img src=/S/flags/Ontario.gif border=0 alt=Ontario width=30 height=18> <img src=/S/flags/Canada.gif border=0 alt=Canada width=30 height=18>
    Unfortunately common sense isn't so common!!
    Visit my website for useful Word, Excel and Access code, templates and Add-Ins

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

    Re: Can I tag a variable value onto a label name? (Word 2002)

    I assume the labels are on a userform. If so, try replacing<pre>With Label & i</pre>

    by<pre>With Me.Controls("Label" & i)</pre>

    If not, post back.

  4. #4
    2 Star Lounger
    Join Date
    Nov 2001
    Posts
    119
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Can I tag a variable value onto a label name? (Word 2002)

    Bryan, Hans, thanks very much!

    You have saved me a lot of code [img]/forums/images/smilies/smile.gif[/img]

Posting Permissions

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