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

indexing through a lot of text boxes

Status
Not open for further replies.

jpl458

Technical User
Sep 30, 2009
337
US
I have a series of text boxes labled D01H1..D01.H16. I want to be able to set properties on these text boxes in a loop with the following code (that is test code, to see if the addressing of the text boxes works). I have included three abortive attempts at addressing the text boxes using the loop counter.

Thanks in advance

Private Sub Doit_Click()
Dim red As Integer
Dim blue As Integer
Dim green As Integer
red = 0
blue = 0
green = 0
For I = 1 To 16
Me.D01HI.BackColor = RGB(red, blue, green)
'Me.D01H& I.BackColor = RGB(red, blue, green)
'Me.D01H(I).BackColor = RGB(red, blue, green)
red = red + 1
Next
End Sub


jpl
 
Replace this:
Me.D01HI.BackColor
with this:
Me.Controls("D01H" & I).BackColor

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
Thats the ticket, worked like a champ. Now i gotta learn about Control (function?)

Thanks for the late nite response

jpl
 
How are ya jpl458 . . .

In the [blue]Tag[/blue] property of the controls in question, put a question mark [purple]?[/purple] [blue](no quotations please!)[/blue] Then replace your code with the following:
Code:
[blue]   Dim red As Integer, blue As Integer, green As Integer, ctl As Control
   
   red = 0
   blue = 0
   green = 0
   
   For Each ctl In Me.Controls
      If ctl.Tag = "[purple][b]?[/b][/purple]" Then
         ctl.BackColor = RGB(red, blue, green)
      End If
   Next[/blue]

See Ya! . . . . . .

Be sure to see thread181-473997 [blue]Worthy Reading![/blue] [thumbsup2]
Also faq181-2886 [blue]Worthy Reading![/blue] [thumbsup2]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top