Lets say that on a form you have multiple
check boxes and any combination of the three can be
selected. If each check box has a different value, how
can you calculate the sum of the marked check boxes?
Spam:
Check boxes don't really have a value besides "True", "False" or "Null" so we'll have to add a field to put our value in to: Lets name it TxtBoxName. Build a bit of code like this:
Private Sub WhatsTheValue()
Dim dblChkBoxVal As Double
dblChkBoxVal = 0
If Me.CheckBox1 = -1 Then dblChkBoxVal = dblChkBoxVal + 5 '5 being the value you want when check box 1 is clicked true
If Me.CheckBox2 = -1 Then dblChkBoxVal = dblChkBoxVal + 100 '100 being the value you want when check box 2 is clicked true
If Me.CheckBox3 = -1 Then dblChkBoxVal = dblChkBoxVal + 12 '12 being the value you want when check box 3 is clicked true
Me.TextBoxName = dblChkBoxVal
End Sub
And/or paste it in to your forms VB module.
Make sure to set the default value of each check box to true or false and also make sure that each check boxes' "Triple State" property says "No". In each of the check boxes "after update" events in the VB environment type in WhatsTheValue . This will work for you!
I believe your typing was fine. Where did you paste in the "Sub" from above? It should be pasted anywhere in your forms module but not within another "Sub"..."End Sub". Give this a check over and write back... Gord
ghubbell@total.net
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.