Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Changing Label Names with Code?

Status
Not open for further replies.

Guest_imported

New member
Jan 1, 1970
0
I was wondering if I could use VBA to change the name of a label on a form. For example, I have 20 labels named Label1, Label2, Label3,... and so on. Is there a way that I can use something like:

Dim lbl As Label
For num = 0 To 20
lbl.Name = "Label" & num
lbl.Caption = DLookup(something)
Next

I can't get it to work. Thanks.
 
Actually what I do if I need to change the name of a label is instead of using a label, I'll use a control and make it uneditable in the form but in the vb section change the value of the control:

Me![control name].Value = "Employee:"

Where you place this will depend on when in the form you need to change the label name.

Hope this helps!

Chris
 
try Forms!YourFormName("Label" & Num).Caption = Whatever. Of course, your DLookup would need to return a string. I am at work and cannot test the above, but I know you are close with the code you have.

Break it into 2 pieces. Set it to = "My test" & Num or whatever and then add the DLookup when everything is working the way you want it to.

Good Luck!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top