iterate through controls

G

Guest

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
 

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