Form VB

A

Ashley

I have about 100 checkboxes on my form.
If all checkboxes are true then the result checkbox is
true. If any of 100 checkboxes are false then the result
check box is false. Rather than writing out 100 checkboxes
field names in my IF statement, is there a short version?

Thanks
Ashley
 
J

Joel

Dim Ctl as Control

For Each Ctl in Me.Controls
If TypeOf Ctl is CheckBox then
If Ctl.Value=True then
' yada yada yada
End If
End If
Next
 
M

MikeB

Private Sub cmdValidateCheckboxes_Click()
If ValidateCheckboxes = False Then
MsgBox "Not all are checked"
Else
MsgBox "All Are Checked"
End If
End Sub

Private Function ValidateCheckboxes() As Boolean
Dim ctrl As Control
ValidateCheckboxes = True 'set to true first
For Each ctrl In Me.Controls
If ctrl.ControlType = acCheckBox Then
If ctrl.Value = False Then
ValidateCheckboxes = False
Exit Function

End If
End If
Next ctrl
End Function
 
M

MikeB

Mike Painter said:
Ashley said:
I have about 100 checkboxes on my form.
If all checkboxes are true then the result checkbox is
true. If any of 100 checkboxes are false then the result
check box is false. Rather than writing out 100 checkboxes
field names in my IF statement, is there a short version?

Thanks
Ashley
Dim varX As Variant
varX = DLookup("[checkbox]", "yourtablename", "[checkbox] = false")
If isnull(varx) then result = trueend if
This is the lazy way.
It would be much faster to open a query thatdoes the same thing and check
that.
Probably not important if you use it in a form but *MUCH*faster than using

The speed difference would be undetectalbe by the user, even if it were
possible to have a thousand checkboxes, it would be done in the blink of your
eye.

Further, the only way the loop goes to completion through all controls is if the
result is true as it exits the loop on discovery of the first unchecked box.
 

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