How to Use Nz Function to Stop Missing-Value Errors in Access Queries
How to use the null-to-zero (Nz) function to prevent expressions in Access query fields causing errors due to null or missing data.
Last updated on 2021-10-12 by David Wallis.
“We're working on a query in Access. The query has two fields — ‘Number1’ and ‘Number2’ — that can contain a number or a null. When we create an expression field in the query, Total:[Number1]+[Number2], the total works out fine when both Number1 and Number2 contain numbers.
“The problem comes when one of them is null because the total then becomes null. This is not what we want of course.
“What do we do?”
A simple solution to your problem is to use the Nz (null-to-zero) function. Try modifying your expression field to this:
Note that when both Number1 and Number2 have null values, Total returns zero.
Microsoft Access 97, 2000, 2002 (XP), 2003, 2007, 2010, 2013, 2016, 2019 and Microsoft 365 will respond similarly to the Nz function applied in this way.
Hello to the Nz Function
The full syntax of the Nz function is this:
The value_to_assess is the value you want the function to assess.
The value_if_null is what you want the function to return when value_to_assess is itself a null value. This argument is optional. If you omit it from your formula, then Nz assumes it is to assume the value zero
Null stands for no value at all.
You can use the Immediate Window in Access’s Visual Basic Editor to test how the Nz function works. Copy and paste any of the examples below into your Immediate Window and then press Enter to see the result.
The wordsMissing value
Your Support for DMW TIPS
Please support this website by making a donation to help keep it free of advertising and to help towards cost of time spent adding new content.
To make a contribution by PayPal in GBP (£ sterling) —
To make a contribution by PayPal in USD ($ US) —
Thanks, in anticipation.
DMW Consultancy Ltd does not accept any liability for loss or damage to data to which any techniques, methods or code included in this website are applied. Back up your data; test thoroughly before using on live data.