For Each...Next

T

Ted

Hi all,

I have several forms with a lot of check boxes on it. Each checkbox
represents a form that will print out if its corresponding check box is
checked. instead of writing an if...then statement for each checkbox i would
rather write code that will automatically check all checkbox controls on the
form to see if its checked. i think i can do this with For...Each?

Help please

Thanks in Advance
Ted
 
H

Howard Kaikow

vba does not have control arrays, so you have to work around the problem.

one way is to use a for each to cycle thru all the controls in the form,
check if the control

other methods require using some method to identify the controls, such as
common root names such as chk001, chk002, etc. Or by using the index or tab
order of the controls.
 
J

Jonathan West

Ted said:
Hi all,

I have several forms with a lot of check boxes on it. Each checkbox
represents a form that will print out if its corresponding check box is
checked. instead of writing an if...then statement for each checkbox i
would
rather write code that will automatically check all checkbox controls on
the
form to see if its checked. i think i can do this with For...Each?

Hi Ted

Something like this should do the needful

Dim oControl as Control
For each oControl in Me.Controls
If TypeOf oControl is MSForms.Checkbox Then
'put your code here
End IF
Next oControl


--
Regards
Jonathan West - Word MVP
www.intelligentdocuments.co.uk
Please reply to the newsgroup
Keep your VBA code safe, sign the ClassicVB petition www.classicvb.org
 

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