microsoft access help database programing developer
Back to Access Experts About Access Experts Access Experts Websites Access Experts Team Access Experts Services Access Experts Case Studies Access Expert Tips Contact Access Experts OUR BLOG
 
 
Problem with null fields and calculated query columns
by Juan Soto
06/26/2007

When calculating formulas as query columns, avoid null data.
Null Values Can Throw Off Your Queries
I love the flexibility of Access queries, they provide a wide range of options to do many wonderful things. Recently, I was working on a project for a client were I was using multiple fields in a table to do calculations when I noticed blanks in some rows where did should have been values. That's when I discovered null values can throw off my calculations.

My calculations were straight forward, the table had columns for PremiumReceived and Refunds. I wanted to calculate the net received by subtracting the Refund amount from the PremiumReceived:
NetReceived: [PremiumReceived] - [Refunds]

Net received was a calculated column in my query and not a column in the table, which was a linked SQL Server table. The problem was that sometimes there was a value of 0 in the Refunds column and sometimes there was a null, (nothing). Thus, some records were null even if the PremiumReceived was greater than zero, because Refunds was null. 

Use Default Values to Solve the Problem
I fixed the issue by using an update query to replace all null values in Refund to zero, modifying the SQL Table properties so that the default value is zero then refreshing the link in Access.

If you can't modify the table properties, another solution would be to modify the formula in the query to:
NetReceived: iif(isNull([Refunds], [PremiumReceived] , [PremiumReceived] - [Refunds])

If you like this tip you will be delighted with our service! Call or write us today for a free quote regarding your computer needs.

Publish this article in your own corporate newsletter or publication! Contact us to obtain a free license.


Home | About Us Why PCExperts | Team | Services | Newsletter | Contact Us
Copyright © 2004