Type Property (Field Object)

Type Property (Field Object)

The Type property returns the data type of the Field object. Read-only.

Syntax

objField.Type

Data Type

Integer

Remarks

The Type property contains the data type of the Field object and determines the range of valid values that can be supplied for the Value property. You set the Type property when you first create the field by setting the Class parameter of the Fields collection's Add method. After that, you cannot change the Type property.

Valid data types are as follows:

Type

Description

Decimal value

OLE variant type

MAPI property type

vbArray

Multivalued type

8192

VT_ARRAY

PT_MV_FLAG

vbBlob

Binary (unknown format)

65

VT_BLOB

PT_BINARY

vbBoolean

Boolean

11

VT_BOOL

PT_BOOLEAN

vbCurrency

8-byte integer (scaled by 10000)

6

VT_CY

PT_CURRENCY

vbDataObject

Data object

13

VT_UNKNOWN

PT_OBJECT

vbDate

8-byte real (date in integer, time in fraction)

7

VT_DATE

PT_APPTIME

vbDouble

8-byte real (floating point)

5

VT_R8

PT_DOUBLE, PT_R8

vbEmpty

Not initialized

0

VT_DEREF

PT_UNSPECIFIED

vbInteger

2-byte integer

2

VT_I2

PT_I2 PT_SHORT

vbLong

4-byte integer

3

VT_I4

PT_I4, PT_LONG

vbNull

Null (no valid data)

1

VT_NULL

PT_NULL

vbSingle

4-byte real (floating point)

4

VT_R4

PT_FLOAT, PT_R4

vbString

String

8

VT_BSTR

PT_TSTRING

vbVariant

Variant (object of unknown type)

12

 

PT_UNSPECIFIED

The current version of CDO does not support the vbNull and vbDataObject data types. The vbEmpty data type should never appear as the value of the Type property because the Add method should derive the data type from the new field's value if the Class parameter is set to vbEmpty.

The vbArray data type must always be used in conjunction with one of the other types, for example vbArray + vbString. The entire array must be of the same data type. Note that operations such as comparison cannot be done with a single operator on types involving vbArray.

When you use a multivalued field in conjunction with an array, you must declare the array to be of the appropriate data type. The data type depends on whether you are writing to the field or reading from it, because a multivalued field accepts arrays of various data types but always returns a vbVariant array. To write to the field, that is, to copy an array to it, declare the type of the array the same as the base type of the field:

Dim Codes(10) As Integer ' NOT just Dim Codes(10)
' ...
Set objCodesField = objFieldsColl.Add("Codes", vbArray + vbInteger)
objCodesField.Value = Codes
 

Failure to do this results in a CdoE_INVALID_TYPE error. To read from the field, that is, to copy it to an array, declare the array as Variant:

Dim Tags(10) As Variant ' NOT Dim Tags(10) or Dim Tags (10) As Long
' ... instantiate object objSource exposing objTagsField ...
Set objTagsField = objSource.Fields.Item("Tags")
objTagsField.Value = Tags
 

Failure to do this results in a VB compiler error.

MAPI stores all custom properties that represent date and time information using Greenwich Mean Time (GMT), also known as Coordinated Universal Time (UTC). CDO converts these properties so that the values appear to the user in local time.

Example

' Fragment from Fields_Add; uses the type "vbString"
    Set objNewField = objFieldsColl.Add( _
                      Name:="Keyword", _
                      Class:=vbString, _
                      Value:="Happiness")
'  verify that objNewField is a valid Field object
' Fragment from Field_Type; display the decimal type value
    MsgBox "Field type = " & objOneField.Type
 

See Also

Concepts

Field Object