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