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 Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Variable as Part of Object Name (Label) 2

Status
Not open for further replies.

GGleason

Technical User
Mar 22, 2001
321
US

I want to change the caption of a label in a form by using a variable. During module execution, I have a variable called strLabel that is set to the label name. Note that the variable is part of the object name, not the object's value. I then have module code like the following:

Application.Forms("frmTools")!(strLabel).Caption = "Hammer"

But this syntax is not correct (it turns red).

What should the syntax be?

TIA,
GGleason
 
Code:
    For Idx = 30 To 41
        MyCtrlName = "Cmd" & Trim(str(Idx))
        Me(MyCtrlName).Caption = "CMMD" & Trim(str(Idx))
    Next Idx

The above 'works'. The Form has a set of command buttons (Cmd30 through cmd41). In my example, "Me" replaces
Application.Forms("frmTools")!

and (MyCtrlName) replaces

(strLabel)


MichaelRed
m.red@att.net

There is never time to do it right but there is always time to do it over
 

Michael,

Your comment made me attempt some minor code changes with success. The syntax I was looking for is as follows (orange colored text):

Application.Forms("frmTools").controls(strLabel).Caption = "Hammer"

Thanks,
GGleason
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top