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

Creating A Sum Field

Status
Not open for further replies.

SILLEYJ

MIS
Jan 25, 2000
43
GB
I have 4 fields R1, R2, R3, and R4 with a value of 0,1,or 2. Is there a way to have access automatically total these 4 fields in a field R5? Thanks in advance

Jeff
 
Hi

On a report/form put a text box with its control source as
=[R1]+[R2]+[R3]+[R4]
 
All that appears to do is take the values on display them in the R5 field
R1 = 1
R2 = 2
R3 = 0
R4 = 1
R5 = 1201

In the control field of R5 I have =[R1]+[R2]+[R3]+[R4]

Jeff
 
Hi Jeff

Sorry I presumed your fields are numeric which will make the above work, if they are text you get the result you got.
Eddie
 
Hi!

Sorry to barge in, but it seems your textboxes contains text, and not numbers. So the result is a concatination of the text, and not the sum of the numbers.

Either go to the table and change from text to numbers, or do conversion. For instance, if those numbers cannot be negative and less den 255, try:

=cbyte(r1)+cbyte(r2)+cbyte(r3)+cbyte(r4)

For larger numbers cint, clng, for decimals csng, cdbl (check out the help on these functions)
 
Thanks, Yes that was my fault as I had not changed the properties of the boxes. Now it is working correctly adding up the values but how do I put that value (R5) into my table with all of the other values?
 
Hi Jeff

Use an update query
UPDATE Table1 SET Table1.R5 = [R1]+[R2]+[R3]+[R4];

replace Table1 with the name of your table.

All the Best
Eddie
 
If you want a SELECT query to return the new field then

Select R1, R2, R3, R4,
(Val(R1) + Val(R2) + Val(R3) + Val(R4)) As R5
From tbl

should do it
 
Thanks for all that they worked flawlessly appreciate all the help.

Jeff
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top