Adding two Numbers Together (1 Viewer)

scgoodman

scgoodman
Local time
Today, 18:08
Joined
Jun 6, 2008
Messages
87
I am trying to add (2) numbers together. I have a sum of transportation charges and Fuel Charges.

I tried: [Transportation] + [Fuel]

It keeps coming up blank.

Suggestions.
 

MSAccessRookie

AWF VIP
Local time
Today, 18:08
Joined
May 2, 2008
Messages
3,428
I am trying to add (2) numbers together. I have a sum of transportation charges and Fuel Charges.

I tried: [Transportation] + [Fuel]

It keeps coming up blank.

Suggestions.



We might need more information to help you to work this out, but if what you are trying to do is get the sum of two Columns from a Database Table, then two obvious things to look for are:
  1. Do both of the Columns contain Numeric type data?
  2. Does either (or both) of the Columns contain a Null Value?
 

scgoodman

scgoodman
Local time
Today, 18:08
Joined
Jun 6, 2008
Messages
87
Yes, some of the values are null.
 

DCrake

Remembered
Local time
Today, 23:08
Joined
Jun 8, 2005
Messages
8,632
Then you need to compensate for this using the Nz() function

Total:Nz([Field1],0)+Nz([Field2],0)
 

guinness

Registered User.
Local time
Today, 15:08
Joined
Mar 15, 2011
Messages
249
Ok I'm glad it worked but I'd like to know why. What does NZ do?
 

DCrake

Remembered
Local time
Today, 23:08
Joined
Jun 8, 2005
Messages
8,632
Nz() is a new and improved function that replaced the A97 NullToZero() function. The added improvement to this is that the earlier function only changed a null value to zero, whereas Nz() allows you to use any replacement value you want.

For Example

Yesterday = Nz([AnyDate],Date()-1)

Therefore if their is no value in the anydate field it will replace it with yesterday's date.

Likewise lets say you are doing a calculation and one side of the equasion = 0 you could get a division by zero error, so if you then used the Nz() like Nz([AnyValue],1) would eliminate the error as timesing anything by one will give you the same figure.

Hope That helps:)
 

guinness

Registered User.
Local time
Today, 15:08
Joined
Mar 15, 2011
Messages
249
Thanks David. That's the best most concise explanation I've had in a while. I've never used NZ before but, now I know that it exists I can see where it could have solved a few problems for me.

Cheers
 

Users who are viewing this thread

Top Bottom