This MSAccess tutorial explains how to use the Access Nz function with syntax and examples.
The Microsoft Access Nz function lets you return a value when a variant is null.
The syntax for the Nz function in MS Access is:
Nz ( variant, [ value_if_null ] )
variant is a variable that is a variant datatype.
value_if_null is optional. It is the value to use when the variant is a null value. If this parameter is omitted and the variant is a null value, the Nz function will return a zero or a zero-length string.
The Nz function can be used in the following versions of Microsoft Access:
Let's look at how to use the Nz function in MS Access:
Nz (varName, "n/a")
The example above would return the value 'n/a' if the variable varName contained a null value.
The example above would return a zero-length string if the variable varName contained a null value.
The Nz function can be used in VBA code in Microsoft Access.
Dim LOption As String LOption = Nz(varChoice, "Not Found")
In this example, the variable called LOption would now contain value in the varChoice variable unless it was a null value. If the varChoice variable contains a null value, the Nz function will return "Not Found".
You can also use the Nz function in a query in Microsoft Access.
In this query, we have used the Nz function as follows:
Expr1: Nz([CategoryName],'Not Found')
This query will evaluate whether the CategoryName field contains a null value and display the results in a column called Expr1. You can replace Expr1 with a column name that is more meaningful.
So in this example, if the CategoryName field contains a null value, the Nz function will return "Not Found". Otherwise, it will return the value from the CategoryName field.
Category: Nz([CategoryName],'Not Found')
The results would now be displayed in a column called Category.
(scroll to see more)