Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Rhinorhino on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Loop through all controls on a form?

Status
Not open for further replies.

gusbrunston

Programmer
Joined
Feb 27, 2001
Messages
1,234
Location
US
Hi:

I've seen this, used it, but can't find it now.

How do I loop through all the controls on a form and do something in each one?

In pigeon basic:
Code:
I = 1
While not end of file
   Look at control(I)
   Do Something
   I = I + 1
Wend

End

I'd appreciate the function (or whatever) for doing this in the form module.

Many thanks,



Gus Brunston 8-: An old PICKer, using Access2000. I manage Suggestions welcome. padregus@attbi.com
 
Use "For Each"

Dim ctrl as Control

For Each ctrl In Forms!MyForm.Controls
'Do something wth ctrl
Next
 
You might also want to check for control type before you do whatever.

Dim ctrl as Control

For Each ctrl In Forms!MyForm.Controls
If ctrl.controltype = acTextBox
'Do something wth ctrl
End if
Next
 
Hi:
Thanks to you both, I'm getting closer to what I want to accomplish. If I'm successful, I'll share it with you.
Cheers, Gus Brunston [glasses] An old PICKer, using Access2000. I manage Suggestions welcome. padregus@attbi.com
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top