control indexes

R

Ra

Hi All,

How do I find the control indexes on a form, etc. I would like to write a
little sub to initialize the controls on a form, and rather than referencing
each I'd like to for-next and use index numbers. Nothing in Properties that I
can see.

Thank you,

Ra
 
A

Allen Browne

Simplest way to loop through the controls on a form would be:
Dim ctl As Control
For each ctl in Me.Controls
Debug.Print ctl.Name
Next

If you really want to use index numbers:
Dim i As Integer
For i = 0 to Me.Controls.Count -1
Debug.Print Me.Controls(i).Name
Next
 
R

Ra

Thank you so much Allen.

Allen Browne said:
Simplest way to loop through the controls on a form would be:
Dim ctl As Control
For each ctl in Me.Controls
Debug.Print ctl.Name
Next

If you really want to use index numbers:
Dim i As Integer
For i = 0 to Me.Controls.Count -1
Debug.Print Me.Controls(i).Name
Next
 
Top