IsObject Function

Description

Returns a Boolean value indicating whether an identifier represents an object variable.

Syntax

IsObject(identifier)

The required identifier argument is a variable name.

Remarks

IsObject is useful only in determining whether a Variant is of VarType vbObject. This could occur if the Variant actually references (or once referenced) an object, or if it contains Nothing.

IsObject returns True if identifier is a variable declared with Object type or any valid class type, or if identifier is a Variant of VarType vbObject, or a user-defined object; otherwise, it returns False. IsObject returns True even if the variable has been set to Nothing.

Use error trapping to be sure that an object reference is valid. You can use the IsNothing function determine if an object reference has been set to Nothing.

See Also

IsArray function, IsDate function, IsEmpty function, IsError function, IsMissing function, IsNull function, IsNumeric function, Object data type, Set statement, TypeName function, Variant data type, VarType function.

Example

This example uses the IsObject function to determine if an identifier represents an object variable. MyObject and YourObject are object variables of the same type. They are generic names used for illustration purposes only.

Dim MyInt As Integer, YourObject, MyCheck    ' Declare variables.
Dim MyObject As Object
Set YourObject = MyObject                ' Assign an object reference.
MyCheck = IsObject(YourObject)        ' Returns True.
MyCheck = IsObject(MyInt)                ' Returns False.
Example (Microsoft Access)

The following example uses the IsObject function to check whether an argument passed to the function is an object.

Sub CheckObject(varAny As Variant)
    Dim varX as Variant

    If IsObject(varAny) Then
        Set varX = varAny
    Else
        varX = varAny
    End If
End Sub