TypeName Function

Description

Returns a String that provides information about a variable.

Syntax

TypeName(varname)

The required varname argument is a Variant containing any variable except a variable of a user-defined type.

Remarks

The string returned by TypeName can be any one of the following:

String returned

Variable

object type

An object whose type is objecttype

Byte

Byte value

Integer

Integer

Long

Long integer

Single

Single-precision floating-point number

Double

Double-precision floating-point number

Currency

Currency value

Decimal

Decimal value

Date

Date value

String

String

Boolean

Boolean value

Error

An error value

Empty

Uninitialized

Null

No valid data

Object

An object

Unknown

An object whose type is unknown

Nothing

Object variable that doesn't refer to an object


If varname is an array, the returned string can be any one of the possible returned strings (or Variant) with empty parentheses appended. For example, if varname is an array of integers, TypeName returns "Integer()".

See Also

Data type summary, IsArray function, IsDate function, IsEmpty function, IsError function, IsMissing function, IsNull function, IsNumeric function, IsObject function, Variant data type, VarType function.

Example

This example uses the TypeName function to return information about a variable.

' Declare variables.
Dim NullVar, MyType, StrVar As String, IntVar As Integer, CurVar As Currency
Dim ArrayVar (1 To 5) As Integer
NullVar = Null                                ' Assign Null value.
MyType = TypeName(StrVar)                ' Returns "String".
MyType = TypeName(IntVar)                ' Returns "Integer".
MyType = TypeName(CurVar)                ' Returns "Currency".
MyType = TypeName(NullVar)                ' Returns "Null".
MyType = TypeName(ArrayVar)                ' Returns "Integer()".
Example (Microsoft Access)

The following example creates several object variables and passes them to the TypeName function.

Sub ObjectTypes()
    Dim dbs As Database, tdf As TableDef
    Dim fld As Field

    ' Get current database.
    Set dbs = CurrentDb
    ' Return TableDef object pointing to Orders table.
    Set tdf = dbs.TableDefs("Orders")
    ' Return Field object pointing to OrderDate field.
    Set fld = tdf.Fields("OrderDate")
    ' Print value returned by TypeName for each object.
    Debug.Print TypeName(dbs)
    Debug.Print TypeName(tdf)
    Debug.Print TypeName(fld)
End Sub
Example (Microsoft Excel)

This example displays the Visual Basic object type of the selection. You can run this example with cells selected, with a single oval selected, or with several different graphic objects selected.

Worksheets("Sheet1").Activate
MsgBox "The selection object type is " & TypeName(Selection)