Sum variant fields

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

How can I sum two fields defined as variant?

They must be defined as variant because I use the IsNull function to set
empty fields to zero (because SUM function doesn't recognize Null values).
But now "field1+field2" gives "field1field2" and not the sum of the values!
 
If "field1+field2" gives "field1field2" then I suspect you've got syntax
problems. Are you doing this in a query or a module. Post your actual code
or SQL.
 
Francisco said:
How can I sum two fields defined as variant?

They must be defined as variant because I use the IsNull function to set
empty fields to zero (because SUM function doesn't recognize Null values).
But now "field1+field2" gives "field1field2" and not the sum of the values!


All table/query fields are variants as are control values.

All aggregate functions, including Sum, ignore Null values,
so there is nothing for you to worry about with that. Maybe
your problem with Sum is because it only operates on
**fields** in a table/query, it is unaware of **controls**
on a form or report. Be sure to keep the distinction
between field and control clear in your mind.

Note that you can use the Nz function to use any value you
want for a Null value. In this case I think you were asking
about Nz(field1, 0)

If field1 + field2 yields the concatenation of the two
values, then at least one of the values is a string value.
Check the source of the value to make sure you understand
what the value really is. If you have a Text field in a
table that represents a number and you want to add it to a
numeric value, then use a conversion functions, e.g.
CLng(field1) + field2 or whatever combination is needed.
 
Back
Top