Provided by Allen Browne, allen@allenbrowne.com. Updated June 2006.
TableInfo() function
This function displays in the Immediate Window (Ctrl+G) the structure of any table in the current database.
For Access 2000 or 2002, make sure you have a DAO reference.
The Description property does not exist for fields that have no description, so a separate function handles that error.
The code
Function TableInfo(strTableName As String)
On Error GoTo TableInfoErr
Dim db As DAO.Database
Dim tdf As DAO.TableDef
Dim fld As DAO.Field
Set db = CurrentDb()
Set tdf = db.TableDefs(strTableName)
Debug.Print "FIELD NAME", "FIELD TYPE", "SIZE", "DESCRIPTION"
Debug.Print "==========", "==========", "====", "==========="
For Each fld In tdf.Fields
Debug.Print fld.Name,
Debug.Print FieldTypeName(fld),
Debug.Print fld.Size,
Debug.Print GetDescrip(fld)
Next
Debug.Print "==========", "==========", "====", "==========="
TableInfoExit:
Set db = Nothing
Exit Function
TableInfoErr:
Select Case Err
Case 3265&
MsgBox strTableName & " table doesn't exist"
Case Else
Debug.Print "TableInfo() Error " & Err & ": " & Error
End Select
Resume TableInfoExit
End Function
Function GetDescrip(obj As Object) As String
On Error Resume Next
GetDescrip = obj.Properties("Description")
End Function
Function FieldTypeName(fld As DAO.Field) As String
Dim strReturn As String
Select Case CLng(fld.Type)
Case dbBoolean: strReturn = "Yes/No"
Case dbByte: strReturn = "Byte"
Case dbInteger: strReturn = "Integer"
Case dbLong
If (fld.Attributes And dbAutoIncrField) = 0& Then
strReturn = "Long Integer"
Else
strReturn = "AutoNumber"
End If
Case dbCurrency: strReturn = "Currency"
Case dbSingle: strReturn = "Single"
Case dbDouble: strReturn = "Double"
Case dbDate: strReturn = "Date/Time"
Case dbBinary: strReturn = "Binary"
Case dbText
If (fld.Attributes And dbFixedField) = 0& Then
strReturn = "Text"
Else
strReturn = "Text (fixed width)"
End If
Case dbLongBinary: strReturn = "OLE Object"
Case dbMemo
If (fld.Attributes And dbHyperlinkField) = 0& Then
strReturn = "Memo"
Else
strReturn = "Hyperlink"
End If
Case dbGUID: strReturn = "GUID"
Case dbBigInt: strReturn = "Big Integer"
Case dbVarBinary: strReturn = "VarBinary"
Case dbChar: strReturn = "Char"
Case dbNumeric: strReturn = "Numeric"
Case dbDecimal: strReturn = "Decimal"
Case dbFloat: strReturn = "Float"
Case dbTime: strReturn = "Time"
Case dbTimeStamp: strReturn = "Time Stamp"
Case 101&: strReturn = "Attachment"
Case 102&: strReturn = "Complex Byte"
Case 103&: strReturn = "Complex Integer"
Case 104&: strReturn = "Complex Long"
Case 105&: strReturn = "Complex Single"
Case 106&: strReturn = "Complex Double"
Case 107&: strReturn = "Complex GUID"
Case 108&: strReturn = "Complex Decimal"
Case 109&: strReturn = "Complex Text"
Case Else: strReturn = "Field type " & fld.Type & " unknown"
End Select
FieldTypeName = strReturn
End Function