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

Create Loop for Collection Add method 1

Status
Not open for further replies.

bajo71

Programmer
Aug 6, 2007
135
US
Hello,

Rather than adding 27 text boxes to a collection individually, I am trying to create a loop. However, I keep receiving numerous error messages. Is there a way I can set the variable in the loop as a string or variant, but then change the type to Control in add method line?

Here's what I have...

Dim colTxtBox As Collection, i As Integer, ctl As Control, txtRef As Variant
Set colTxtBox = New Collection

For i = 1 To 27
txtRef = "Me.Text" & i
colTxtBox.Add txtRef
Next i

For Each ctl In colTxtBox
ctl.Enabled = False
Next

Many thatnks
 
You add text to the collection, next refer to collection items as Control typed.
You should rather use colTxtBox.Add Me.Controls("TextBox" & i

combo
 
Makes perfect sense thank you so much!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top