Null

This keyword/value can only be used in conjunction with the Variant data type.
This keyword/value is used when a variable declared as variant does not contain any valid data.
This data type can be thought of as defining an unknown value.
This keyword cannot be assigned to variables of other data types.
The Null data type can be assigned explicitly to indicate that the variable has no data.
A Null value is normally used to indicate an invalid value or error.
The Null data type can only be assigned explicitly.

Dim myVariant As Variant 
myVariant = Null

IsNull Function

You can test a variable for a null value using the ISNULL
This function return True or False indicating if a variable (or expression) does not contain any data.

Dim myVariant As Variant 
myVariant = Null
If (IsNull(myVariant) = True) Then
   Call MsgBox("null value")
End If

You cannot use "myVariant = Null" to test for a null value


Null Values in a Expression

If any of the values in an expression have been assigned the value Null then the result will also be Null.

Dim myVariant1 As Variant 
Dim myVariant2 As Variant
Dim myResult As Variant

myVariant1 = 30
myVariant2 = Null
myResult = myVariant1 + myVariant2
If (myResult = Null) Then
End If

vbVarType.vbNull

This cannot be used to assign a Null Value.
If you assign a variable to vbNull you are actually assigning a value of 1 or "1".


VarType Function

Dim myVariant As Variant 
myVariant = Null
If (VarType(myVariant) = vbNull) Then
End If

Important

If you assign a Null value to a variable of a different data type you will generate a run-time error "Invalid use of Null".


© 2019 Better Solutions Limited. All Rights Reserved. © 2019 Better Solutions Limited TopPrevNext