Adding Checkboxes

brett429

Registered User.
Local time
Today, 09:59
Joined
Apr 3, 2008
Messages
114
I have several checkboxes (let's say 10) in a form as well as an unbound field which will be used to calculate how many of the checkboxes are checked. So, if 3 of the 10 boxes are checked, I want the unbound field to display "3"... if one is unchecked, it should go down to "2" etc. etc.

How can this be done? I thought about adding an onClick event to each checkbox that would increase the field by 1 (else, decrease by 1)... but I can't figure out how to do it. Thanks!
 
This give you any ideas?

Code:
  Dim ctl           As Control
  Dim intCount      As Integer

  For Each ctl In Me.Controls
    Select Case ctl.ControlType
      Case acCheckBox
        If ctl.Value = True Then
          intCount = intCount + 1
        End If
    End Select
  Next ctl
  MsgBox intCount
 
A check box has a value of 0 when unchecked and a value of -1 when checked.

So couldn't you just put something like;

Code:
=([check1]+[check2]+......[checkX])*-1

in the control source of the textbox?
 
You could, but a checkbox can conceivably be Null, so you'd have to account for that. You would also have to change the code if you added/subtracted checkboxes, so I like the loop better.
 
Me.TextBoxName = intCount
 
A check box has a value of 0 when unchecked and a value of -1 when checked.

So couldn't you just put something like;

Code:
=([check1]+[check2]+......[checkX])*-1

in the control source of the textbox?

This actually worked great (so did the previous suggestion). Thanks, guys!
 

Users who are viewing this thread

Back
Top Bottom