iterate through controls

S

smk23

How do I iterate through all the controls on a form? Currently I have:

Dim ct AS Access.Control

For Each ct In Forms("frmMyForm").Controls
..code
Next ct

I get an error that it can't find the form when I'm in the form itself and
spelling looks correct.

Thanks
 
R

Rick Brandt

smk23 said:
How do I iterate through all the controls on a form? Currently I have:

Dim ct AS Access.Control

For Each ct In Forms("frmMyForm").Controls
..code
Next ct

I get an error that it can't find the form when I'm in the form
itself and spelling looks correct.

Thanks

I see nothing wrong with what you have, but I've always just used...

Dim ctl As Control

For Each ctl in Me
....
 
D

Douglas J. Steele

If the code's in the module associated with the form, you can use

For Each ct In Me.Controls
 
Top