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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top