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!

maniuplating controls using strings 1

Status
Not open for further replies.

striker73

MIS
Jun 7, 2001
376
US
I have 12 labels on my form named lblWorkOrder1, lblWorkOrder2, etc. I want to be able to use a for loop to manipulate the controls using the following code:

For x = 1 to 12
controlname = "lblWorkOrder" & x
controlname.Visible = False
Next x

The compiler gives me an "invalid qualifier" error, because a string doesn't have a visible attribute. Any ideas on how I can get around this? Thanks!
 
You should check for the type of control. The following Select Case statement checks for the type of control through a For Each loop. You should probably use something like this to do what you are attempting...

Select Case ctl.ControlType
Case Is = acTextBox ' 109
ctl.BackColor = vbYellow
Case Is = acListBox ' 110
ctl.BackColor = vbYellow
Case Is = acComboBox ' 111
ctl.BackColor = vbYellow
Case Is = acCheckBox ' 106
End Select

Gary
gwinn7
 
Hi!

The syntax you want is like this:

For x = 1 to 12
controlname = "lblWorkOrder" & x
Me.Controls(controlname).Visible = False
Next x

hth Jeff Bridgham
bridgham@purdue.edu
 
Thanks, but I'm not sure how that would help me. Let me try and explain it a little better. I have 12 labels on the form, but I want to be able to display only 3 at a time, if I want. Since the labels are similarly named, I was hoping to be able to use a for loop.

I thought of doing this after I saw the following code that someone posted on here.

For x = 1 to 3
Debug.Print Me("Text" & x).Value
Next x



I was hoping to use something like this:

For x = 1 to 3
'Make labels #1-3 visible
'Display the correct info into each label
Next x


I can get the name of the control in a string (ie: lblWorkOrder1, lblWorkOrder2, etc.) but I don't know how to convert that string into a control. Does that make any sense?
 
Perfect!! That's exactly what I was looking for!! Thanks!!
 
What about...

Me.Controls("MylabelName").Visible

???

Gary
gwinn7




 
Nevermind... I just saw Jebry's response. Good job.

Gary
gwinn7
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top