Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to add up check box sums

Status
Not open for further replies.

spam

Programmer
Nov 29, 2001
17
IE
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?

Thanks in advanced.....
 
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!


Gord
ghubbell@total.net
 
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
 
It works!!!!!!

Thanks For everything
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top