How can I find out how many textboxes I have? Can you count them during runtime?
If you mean the number of them in the array, you can just retrieve it from the
.Count property. For example, if the text boxes are called Text1, then
Text1.Count will tell you the number of occurences. Keep in mind that by default, the indexes start from 0, so if .Count is 3 for instance, then they will be numbered from 0 to 2.
If you mean the number of textboxes in general on the form, then while there are probably better ways, you could try this sample code I just threw into a form in a test project.
- Private Sub Form_Click()
-
Dim c As Control, i As Long
-
For Each c In Me.Controls
-
If TypeOf c Is TextBox Then
-
Debug.Print "Here's one: "; c.Name
-
i = i + 1
-
End If
-
Next
-
Debug.Print "Found "; Format(i); ' text box(es).'
-
End Sub