| View previous topic :: View next topic |
| Author |
Message |
noke Newbie
Joined: 30 Apr 2004 Posts: 3
|
Posted: Apr 30th, 2004 12:30 PM Post subject: Variable as part of object name |
|
|
I'm pretty new to VBA.
Can someone tell me how to reference an object using a variable as part of its name? For example, I'm writing a loop to assign captions to sequentially named Labels. I think the following shows what I'm trying to accomplish.
For i = 1 to 40
Label(i).Caption = "...whatever....."
Next i
Thanks |
|
| Back to top |
|
Andir Centurion

Joined: 21 Dec 2003 Posts: 184 Location: Chicago Area
|
Posted: Apr 30th, 2004 12:43 PM Post subject: |
|
|
Well, you hit it on the head...but, you need to rename all the labels. Set the index property of your "label1" control to 1, and rename it to "label". Do the same for each label you have. Then your code will work.
VB will automatically do this for you if you select yes when it asks you if you want to create a control array when cutting and pasting controls. _________________ If you happen to see little people sitting on your desk...don't tell anyone or they might think your crazy too. |
|
| Back to top |
|
noke Newbie
Joined: 30 Apr 2004 Posts: 3
|
Posted: Apr 30th, 2004 03:40 PM Post subject: |
|
|
Sorry, you'll have to excuse my ineptitude!
Which index property? There is no index property (other than Tab Index) listed in the Properties for the Label object, and if I try to rename more than one Label to "Label" I get an error message.
 |
|
| Back to top |
|
Andir Centurion

Joined: 21 Dec 2003 Posts: 184 Location: Chicago Area
|
Posted: Apr 30th, 2004 05:18 PM Post subject: |
|
|
Which application are you using it in? Access, VB, Excel? _________________ If you happen to see little people sitting on your desk...don't tell anyone or they might think your crazy too. |
|
| Back to top |
|
noke Newbie
Joined: 30 Apr 2004 Posts: 3
|
Posted: May 3rd, 2004 08:26 AM Post subject: |
|
|
| Sorry....Excel |
|
| Back to top |
|
Andir Centurion

Joined: 21 Dec 2003 Posts: 184 Location: Chicago Area
|
Posted: May 3rd, 2004 12:52 PM Post subject: |
|
|
Well, I'm not too familiar with working in Excel with them, but I did find out you can set the index property at runtime. That doesn't help much unless your creating the labels on opening the document, which sucks. I'm stuck as well on this question without more research. Why are you using the label control? Can you use the cells on the sheet to label something? _________________ If you happen to see little people sitting on your desk...don't tell anyone or they might think your crazy too. |
|
| Back to top |
|
|