Controls

  • Thread starter Thread starter Richard Grene
  • Start date Start date
R

Richard Grene

I misstated my earlier post about maximum of 57 controls.

My real question is how to loop through all controls in a form, even if the
control is part of a GroupBox? I want to write some generic code for all my
forms so I don't know ahead of time if the form has any groupbox's. The
following code does not work with groupbox's.

Thanks,
Richard

Dim sControl As Control

For Each sControl In Me.Controls

next sControl
 
Richard,
Control has a Controls collection. You can use Recursion:

' VS.NET 2003 syntax
Sub VisitControls(parent As Control)
For Each child As Control in parent.Controls
VisitControls(child)
Debug.WriteLine(child, child.Name)
Next
End Sub

Elsewhere in a form level procedure you can call the above with:

VisitControls(me)

Remember that Form inherits from Control...

Hope this helps
Jay
 
Back
Top