IsNull Function

See Also1MWJ72C              ExampleIJ12P4>Low

Returns a value that indicates whether or not a Variant8PHEAW3 contains the special Null1DDW7C0 value.

Syntax

IsNull(variant)

Remarks

The argument variant can be any Variant expression.  The IsNull function returns True if the expression contains the Null value; otherwise, it returns False.

The Null value indicates that the Variant contains no data.  Null is not the same as Empty1L2JEZ4, 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.

 

Caution      Using the IsNull function is the only way from within Visual 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.  This is because any expression containing a Null is itself Null and therefore False.

 


See Also

IsDate Function9B784K

IsEmpty Function2K1M5H0

IsNumeric Function1MXC66A

VarType FunctionXRZH1Y


IsNull Function Example

The 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 the loop exits.  To try this example, paste the code into the Declarations section of a form.  Then press F5 and click the form.

 

Sub Form_Click ()

   Dim TestVar                           ' Declare variable.

   TestVar = Null                        ' Initialize as Null.

   Do

      If IsNull(TestVar) Then            ' Evaluate variable.

         MsgBox "TestVar is Null."       ' Indicate if Null.

         TestVar = ""                    ' 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.

End Sub