Adding up scores in a form

T

Tom Tripicchio

I have 5 questions in a form using combo boxes that return a numeric value.
When the last question is answered I would like the total score of the 5
questions (all added together) to appear in a box in the same form. How to I
accomplish this?

Thanks, Tom
 
M

Mr. B

I have 5 questions in a form using combo boxes that return a numeric value.
When the last question is answered I would like the total score of the 5
questions (all added together) to appear in a box in the same form. How to I
accomplish this?

Thanks, Tom

Hi, Tom.

If you only want to see the total results after the user has made a
selection fromt he last of the 5 questions, you can use code in the
After Update event of the last combo box that will accoumplish what
you want.

First, you might also want to check to see that the user has actually
made a selection from all of the combo boxes.

You can create a function that will check for valid data in each of
the combo boxes and only return a total of all values in all of the
combo boxes when a value has been selected in all combo boxes.

The function below will place a zero in the text box "txtTotal" if
there is any combo box that does not have a value greater than zero.

Function ChkForValidData()
If Me.cboBox1 > 0 And Me.cboBox2 > 0 And _
Me.cboBox3 > 0 And Me.cboBox4 > 0 And _
Me.cboBox5 > 0 Then
Me.txtTotal = Val(Me.cboBox1)
Me.txtTotal = Val(Me.txtTotal) + Val(Me.cboBox2)
Me.txtTotal = Val(Me.txtTotal) + Val(Me.cboBox3)
Me.txtTotal = Val(Me.txtTotal) + Val(Me.cboBox4)
Me.txtTotal = Val(Me.txtTotal) + Val(Me.cboBox5)
Else
txtTotal = 0
End If
End Function

You would then place the following code in the After Update event of
eacn combo box:

ChkForValidData

You will need to substitute the names of your combo boxes for the
"cboBox1" etc. and the name of your text box for the "txtTotal" in my
code.

HTH

Mr. B
 
T

Tom Tripicchio

Thanks for the info.

Do I place the if-then code in the text box where I want the score to
appear? If so where in the property section should it be placed. Sorry for
the confusion. A Newbie.
 
B

bhrosey via AccessMonster.com

Tom said:
Thanks for the info.

Do I place the if-then code in the text box where I want the score to
appear? If so where in the property section should it be placed. Sorry for
the confusion. A Newbie.
[quoted text clipped - 48 lines]

The way I did it was just to put a text box on your form that is for the
total and inside it type:
=([box1]+[box2]+[box3]etc...)
 
Top