If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below. |
|
|
Thread Tools | Display Modes |
#1
|
|||
|
|||
adding fields in query
I am trying to add fields in a query to put into a new field. For example;
FieldOne, FieldTwo, and FieldThree should equal FieldFour. FieldOne has a value of 1, FieldTwo has a value of 2 and FieldThree has a value of 3. When I try =FieldOne+FieldTwo+FieldThree in FieldFour with the expression builder, it does not add them, it just shoves all their values together. Instead of FieldFour having a value of 6 when I run the query, it gives me a value of 123. I have also tried the "&" instead of "+", and I get the same results. I have tried changing the Total line to Sum, Group By, Expression, and Count. the query still does the same thing. Access is fairly new to me, so I am sure that there is a simple solution that I am overlooking. Any help provided would be great. TIA |
#2
|
|||
|
|||
adding fields in query
It sounds as if the fields are being treated as if they are TEXT fields.
Try using the Val function or one of the conversion functions (Cdbl) to force the conversion of the text to a number. Of course this will fail if the fields are ever null (blank) or contain a non-numeric value. =CDbl(FieldOne)+CDbl(FieldTwo)+CDbl(FieldThree) To handle nulls in a field combine the VAL function with the NZ function Val(Nz(FieldOne,0)) John Spencer Access MVP 2002-2005, 2007-2010 The Hilltop Institute University of Maryland Baltimore County janelgirl wrote: I am trying to add fields in a query to put into a new field. For example; FieldOne, FieldTwo, and FieldThree should equal FieldFour. FieldOne has a value of 1, FieldTwo has a value of 2 and FieldThree has a value of 3. When I try =FieldOne+FieldTwo+FieldThree in FieldFour with the expression builder, it does not add them, it just shoves all their values together. Instead of FieldFour having a value of 6 when I run the query, it gives me a value of 123. I have also tried the "&" instead of "+", and I get the same results. I have tried changing the Total line to Sum, Group By, Expression, and Count. the query still does the same thing. Access is fairly new to me, so I am sure that there is a simple solution that I am overlooking. Any help provided would be great. TIA |
#3
|
|||
|
|||
adding fields in query
Thank you so much!! They were set as TEXT fields, and once I adjusted that,
it added correctly. This really helped me from pulling out the remainder of my hair! Thanks again. "John Spencer" wrote: It sounds as if the fields are being treated as if they are TEXT fields. Try using the Val function or one of the conversion functions (Cdbl) to force the conversion of the text to a number. Of course this will fail if the fields are ever null (blank) or contain a non-numeric value. =CDbl(FieldOne)+CDbl(FieldTwo)+CDbl(FieldThree) To handle nulls in a field combine the VAL function with the NZ function Val(Nz(FieldOne,0)) John Spencer Access MVP 2002-2005, 2007-2010 The Hilltop Institute University of Maryland Baltimore County janelgirl wrote: I am trying to add fields in a query to put into a new field. For example; FieldOne, FieldTwo, and FieldThree should equal FieldFour. FieldOne has a value of 1, FieldTwo has a value of 2 and FieldThree has a value of 3. When I try =FieldOne+FieldTwo+FieldThree in FieldFour with the expression builder, it does not add them, it just shoves all their values together. Instead of FieldFour having a value of 6 when I run the query, it gives me a value of 123. I have also tried the "&" instead of "+", and I get the same results. I have tried changing the Total line to Sum, Group By, Expression, and Count. the query still does the same thing. Access is fairly new to me, so I am sure that there is a simple solution that I am overlooking. Any help provided would be great. TIA . |
Thread Tools | |
Display Modes | |
|
|