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 wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Sum of fields in a Query

Status
Not open for further replies.

coboldave

MIS
Dec 20, 2001
41
US
Access 2000 / OS win9x/2000/me/xp/pro

How do I add the numerical value of ten fields together and show the result in a DB or Query field

Example: I have a FP2000 form that the results of a simple test is mapped to fields Q1 thru Q10, the values are either "0" or "10". I want to add Q1+Q2+Q3 etc. and display the results in "test_score".
 
If test_score is a field in the underlying table then you would need to calculate the value from the after update event for the last question.

Dim myVal as Integer
myVal = Q1 + Q2 + Q3 + ...Q10
Me.test_score = myVal


Paul
 
I'm not very good at this. Where would the update statement go?
 
You would open the Form in Design View, double click the textbox for Q10 and that should open the Properties box for that control. Scroll down in the properties box until you see the After Update Event (or go to the Events tab and look for After Update). Click on the line and then click the box with the three dots. That will open another box. Click Code Builder. This will create an AfterUpdate event for that textbox. Then put the code between the Private Sub and End Sub lines. When you close it, make sure the words Event Procedure are showing on the line next to the After Update event. Then try it out.

Paul
 
Is it possible to do this in the table field test_score? Then the query would just read the results directly from the test_score field.
 
I for got to put this in: I have a query only. I am trying to disply the results in a Front Page 2000 DB results form
 
Dave, I think the problem here is that you are asking a Front Page question in an Access forum. You are developing your page in FP and only have an Access query that provides your data, so you are going to need to SUM this using a FP command. I am guess Paul is close, it is going to be something like:

FieldOnFormName := Q1 + Q2 + Q3...;

But I am not sure.

Also, I would not have a field in the table that stores the value of the SUM. This is a calculated value and should be SUM'ed at the time of use to make sure your data is valid and current. Terry
**************************
* General Disclaimor - Please read *
**************************
Please make sure your post is in the CORRECT forum, has a descriptive title, gives as much detail to the problem as possible, and has examples of expected results. This will enable me and others to help you faster...
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top