How to get data type name from the field type enumeration

K

kiloez

I am only getting a numerical value for the field type when using VBA to get
the field data types used in a given table, for example:


For Each fld In rst.Fields
FieldType = fld.Type
Next fld

fld.Type returns a numerical value only. How can I get the name instead,
for example: Text, Long Integer, Memo, ect...? Any help would be much
appreciated.
 
S

Stuart McCall

kiloez said:
I am only getting a numerical value for the field type when using VBA to
get
the field data types used in a given table, for example:


For Each fld In rst.Fields
FieldType = fld.Type
Next fld

fld.Type returns a numerical value only. How can I get the name instead,
for example: Text, Long Integer, Memo, ect...? Any help would be much
appreciated.

Access has a built-in function for this purpose: TypeName.

Dim i As Long
Debug.Print TypeName(i)

Result: Long
 
A

Allen Browne

Stuart, the TypeName() function returns the subtype for Variants in VBA,
i.e. it gives the names for VarType() values. This is not the same thing as
the field types.

As an example, vbLong = 3, whereas dbLong = 4.
 
S

Stuart McCall

Allen Browne said:
Stuart, the TypeName() function returns the subtype for Variants in VBA,
i.e. it gives the names for VarType() values. This is not the same thing
as the field types.

As an example, vbLong = 3, whereas dbLong = 4.

Of course <slaps forehead>. I even made a conversion table some time ago.
Late night posting is my only excuse...
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top