Best way to loop thru controls on a form recursively?

What is the most efficient way to loop thru all the controls on a form including controls within container controls?

Who is Participating?
Jacques Bourgeois (James Burger)Connect With a Mentor PresidentCommented:
	Public Sub LoopThroughControls(container As Control)

		For Each ctl As Control In container.Controls
			'Do your stuff here...
			If ctl.Controls.Count > 0 Then
			End If
			'... or here

	End Sub

Open in new window

A form is a Control, so you can send your form to that method, and it will recursively calls itself back when you encounter a Control that contains other Controls.
BlakeMcKennaAuthor Commented:
Thanks James...exactly what I was looking for!
All Courses

From novice to tech pro — start learning today.