contents.gifindex.gifprev1.gifnext1.gif

IsNull

Purpose

Returns a value indicating whether or not a Variant contains the special Null value.

Arguments

IsNull( variant )

Notes

You can use the IsNull function in Access Basic or in an expression. In Access Basic, the argument variant can ben any Variant expression. The IsNull function returns True (-1) if the expression contains the Null value; otherwise, it returns False (0). In an expression, you can use IsNull to determine whether a control or field contains data. The Null value indicates that the Variant contains no data. Null is not the same as Empty, which indicates that a Variant has not yet been initialized. It is also not the same as a zero-length string, which is often referred to as a null string.

Important: Using the IsNull function is the only way from within Access Basic to determine whether or not a Variant expression contains a Null value. Expressions that you might expect to evaluate True under some circumstances, such as If var = Null and If var <> Null, are always False. Because of Null propagation, any expression containing a Null is itself Null and therefore False.

In an expression, you can use IsNull to determine whether a control or field contains data. For example, you could use the following expression in the Condition column of the Macro window to validate the contents of the First Name control on the Employees form. If the expression evaluates true (nonzero), a message could be displayed to alert the user that the field contains no data.

IsNull(Forms!Employees![FirstName])

Tip: In a query, a faster way to check for Null values is by typing "IsNull" in the Criteria row of the QBE grid. For queries that will be passed to ODBC data sources, don't use the IsNull function; instead, use the Is operator with the Null reserved word. For more information on choosing between the IsNull function and Is Null, see Working with Nulls and Zero-Length Strings.

Example

This example evaluates TestVar to determine whether it contains the Null value and then displays an appropriate message. The variable TestVar starts as Null but is changed to a zero-length string the first time through the loop. The second time through the loop, TestVar again becomes Null and ends the loop.

Dim TestVar As Variant
// Declare variable.
TestVar = Null
// Initialize as Null.
Do

If IsNull( TestVar ) Then
// Evaluate variable.
MgBox "TestVar is Null."
// Indicate if Null.
TstVar = ""
// Make zero-length string.
Else

MsgBox "TestVar is not Null."
// Indicate if not Null.
TestVar = Null
// Make Null.
End If

Loop Until IsNull( TestVar )
// Loop until TestVar is Null.