How do you add four numbers in an Access query?

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

Guest

Trying to add four values(four different fields) in a query. When there are
values in all four fields the query works. If a field is empty, the query
does not work.
 
trose said:
Trying to add four values(four different fields) in a query. When
there are values in all four fields the query works. If a field is
empty, the query does not work.

I am not at all sure what you are saying.

Do you mean you want to add four fields to a query? Are they all from
the same record source?

Do you mean you want to add something to a query that is not coming from
an outside record source?
 
Instead of

Field1 + Field2 + Field3 + FIeld4

you need to use

Nz(Field1,0) + Nz(Field2,0) + Nz(Field3,0) + Nz(FIeld4,0)
 
Place a 0 (zero) where it is now blank.

You can have this done automatically by going into your table, setting the
Default Value to 0 (zero), and then set Required to yes. This will force a
zero to be displayed.
 
I assume you have something in your query like "MyCalculatedField = [Field1]
+ [Field2] + [Field3] + [Field4]". This will work fine unless one of the
fields happens to be Null. A single Null will make the entire calculation
return Null. Try the following instead:

MyCalculatedField = nz([Field1],0) + nz([Field2],0) + nz([Field3],0) +
nz([Field4],0)
Nz() "substitutes" the specified value (in this case zero) for Null when it
is encountered. You are only making a substitution in your calculation, not
your data.


HTH,
 
mnature,

A default value of zero for numeric fields is not always appropriate. For
example, if you have a database that tracks daily temperatures for various
cities, and you don't have a given city's temperature value available, it's
much better to leave the field as null (unknown) rather than entering zero.
If this happened for Anchorage, Alaska, who would be the wiser--certainly
zero would seem like a reasonable entry for this city.

It's generally better to use the Nz function to convert nulls on-the-fly, as
needed, rather than force a value.


Tom

http://www.access.qbuilt.com/html/expert_contributors.html
http://www.access.qbuilt.com/html/search.html
__________________________________________
 
Good point. I sometimes concentrate too much on "pure" numbers, and forget
that they are actually representing something in reality.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Back
Top