View Full Version : return the datatype of a column?


bplus
07-04-2006, 09:21 AM
Hi,
I need to create an sql query for an ms access db that will return the data type of a given column.

Can anyone help me? I quite new to sql etc.


thanks in advance!

llkhoutx
07-04-2006, 03:16 PM
Create a column in your table with "intDataType:DataType([YourFieldName])", without the quotes.

RuralGuy
07-04-2006, 03:32 PM
And this is right out of the VBA Help system in Access.
'-- This example demonstrates the Type property by returning
'-- the name of the constant corresponding to the value of
'-- the Type property of all the Field objects in the Employees table
'-- in the NorthWind sample db.
'-- The FieldType function is required for this procedure to run.

'-- It is right out of VBA Help in Access

Sub TypeX2()

Dim dbsNorthwind As Database
Dim fldLoop As Field

Set dbsNorthwind = OpenDatabase("C:\Program Files\Microsoft Office\Access\Samples\Northwind.mdb")

Debug.Print "Fields in Employees TableDef:"
Debug.Print " Type - Name"

' Enumerate Fields collection of Employees table.
For Each fldLoop In _
dbsNorthwind.TableDefs!Employees.Fields
Debug.Print " " & FieldType(fldLoop.Type) & _
" - " & fldLoop.Name
Next fldLoop

dbsNorthwind.Close

End Sub

Function FieldType(intType As Integer) As String

Select Case intType
Case dbBoolean
FieldType = "dbBoolean"
Case dbByte
FieldType = "dbByte"
Case dbInteger
FieldType = "dbInteger"
Case dbLong
FieldType = "dbLong"
Case dbCurrency
FieldType = "dbCurrency"
Case dbSingle
FieldType = "dbSingle"
Case dbDouble
FieldType = "dbDouble"
Case dbDate
FieldType = "dbDate"
Case dbText
FieldType = "dbText"
Case dbLongBinary
FieldType = "dbLongBinary"
Case dbMemo
FieldType = "dbMemo"
Case dbGUID
FieldType = "dbGUID"
End Select

End Function