tech on the net

MS Access: Nz Function

In Microsoft Access, the Nz function lets you return a value when a variant is null.

Syntax

The syntax for the Nz function 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.

Applies To

For Example

Nz (varName, "n/a")

The example above would return the value 'n/a' if the variable varName contained a null value.

Nz (varName)

The example above would return a zero-length string if the variable varName contained a null value.

VBA Code

The Nz function can be used in VBA code. For example:

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".

SQL/Queries

You can also use the Nz function in a query.

Microsoft Access