Iterate through controls collection looking for check boxes

G

Glenn Suggs

Can someone please show me an example of code that will inspect all controls
on a form and set the value to -1 for all check box controls exept for check
boxes having a particular name?

Thanks in advance,
 
W

Wayne Morgan

Example (untested):
Dim ctl As Control
For Each ctl In Me.Controls
If ctl.ControlType = acCheckBox Then
If InStr(ctl.Name, "IsThisInTheName") = 0 Then
ctl = True
End If
End If
Next

Depending on whether or not you've set up the checkboxes in questions with a
common factor to their names (and what that common factor is) you will have
to change the way you check to see if the name of the control matches your
criteria.
 
R

Rafi

You can use a variation of this code

For Each Ctl In Forms("Your Form Name as a String").Controls
If TypeOf Ctl Is Check Box Then
 
R

Rafi

Use a variation of thsi code

For Each Ctl In Forms(Your Form Name as a string).Controls
If TypeOf Ctl Is acCheckBox Then
If ctl.caption <> ? To skip certain controls

End if
End If
Next ctl
 
Top