Control Limit

R

Richard Grene

When looping through controls on a form, there seems to be a limit of 57,
even though there are 75 on the form. This is the code:
Dim sControl As Control

For Each sControl In Me.Controls

next sControl

I looked at the Forms designer Generated Code and me.Controls.AddRange only
contains 57 out of the 75 controls.

Any ideas.

Thanks,
Richard
 
H

Herfried K. Wagner [MVP]

Richard Grene said:
When looping through controls on a form, there seems to be a limit of 57,
even though there are 75 on the form. This is the code:
Dim sControl As Control

For Each sControl In Me.Controls

next sControl

I looked at the Forms designer Generated Code and me.Controls.AddRange only
contains 57 out of the 75 controls.

This code will only enumerate the controls which are placed directly
onto the form, not the controls nested inside containers.
 
T

Tom Spink

Hi, You're seeing this because you have controls as part of other controls,
e.g. checkboxes within a group box, or buttons in a panel (or of course
anything else where there are child controls in a parent control). If this
is the case, you need to perform a recursive search, which searches for
child controls within controls.

--
HTH,
-- Tom Spink, Über Geek

Please respond to the newsgroup,
so all can benefit

"Chaos, Panic, Disorder, my work here is done"


: When looping through controls on a form, there seems to be a limit of 57,
: even though there are 75 on the form. This is the code:
: Dim sControl As Control
:
: For Each sControl In Me.Controls
:
: next sControl
:
: I looked at the Forms designer Generated Code and me.Controls.AddRange
only
: contains 57 out of the 75 controls.
:
: Any ideas.
:
: Thanks,
: Richard
:
:
:
:
 
F

Fergus Cooney

Hi Richard,

If any of the Controls are contained within another Control, eg a Panel,
they will be in the Controls collection of the Panel rather than of the Form.

Regards,
Fergus
 

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

Top