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

For loop with controls 2

Status
Not open for further replies.

mjk9564

Programmer
Apr 23, 2003
64
US
What I'm trying do is write a For Next Loop that will allow me increment a label name by one each time it goes through the loop. I have 14 labels all named the same except for the last digit. I don't know what I would even search for and am not sure if it is possible here is an example of what I would like to do. Any help would be appreciated.

For intLabel = 1 to 14

lblWF310 & intLabel.caption = ![LocationName]
lblWF310 & intLabel.ToolTipText = ![IngredientName]

.movenext

next
 
You need to make your label an array of labels (draw a label onto the form, copy it, and paste it onto the form. It will ask if you want to make an array with the object, then code it like so..

Dim x As Integer
For x = 1 to 14

lblWF310(x).caption = ![LocationName]
lblWF310(x).ToolTipText = ![IngredientName]

.movenext

next
 
mjk9564,

Would it help?

Dim objControl As Control
Dim i As Integer

i = 0

For Each objControl In Me.Controls
If TypeName(objControl) = "Label" Then
i = i + 1
objControl.Caption = "My Label " & CStr(i)
End If
Next objControl

Vladk
 
mjk9564,

I don't think you can increment label names by 1 for the labels that already on the form. You could do it for the label captions.

The best approach for the names is in the LPlates answer: use array while setting the labels.

Vladk
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top