VBA Tipp: Jet-Feldtypen als Zeichenfolge darstellen

Aus DBWiki
Wechseln zu: Navigation, Suche

Problem

Ich möchte die Felddatentypen von Access nicht als Zahlen, sondern im Klartext darstellen.

Lösung

Hierbei hilft die folgende Funktion:

Public Function FieldTypeToString(FieldType As Long) As String
   Select Case FieldType
   Case dbBigInt:     FieldTypeToString = "BigInteger"
   Case dbBinary:     FieldTypeToString = "Binary"
   Case dbBoolean:    FieldTypeToString = "Boolean"
   Case dbByte:       FieldTypeToString = "Byte"
   Case dbChar:       FieldTypeToString = "Char"
   Case dbCurrency:   FieldTypeToString = "Currency"
   Case dbDate:       FieldTypeToString = "Date"
   Case dbDecimal:    FieldTypeToString = "Decimal"
   Case dbDouble:     FieldTypeToString = "Double"
   Case dbFloat:      FieldTypeToString = "Float"
   Case dbGUID:       FieldTypeToString = "Guid"
   Case dbInteger:    FieldTypeToString = "Integer"
   Case dbLong:       FieldTypeToString = "Long"
   Case dbLongBinary: FieldTypeToString = "LongBinary"
   Case dbMemo:       FieldTypeToString = "Memo"
   Case dbNumeric:    FieldTypeToString = "Numeric"
   Case dbSingle:     FieldTypeToString = "Single"
   Case dbText:       FieldTypeToString = "Text"
   Case dbTime:       FieldTypeToString = "Time"
   Case dbTimeStamp:  FieldTypeToString = "TimeStamp"
   Case dbVarBinary:  FieldTypeToString = "VarBinary"
   Case Else:         FieldTypeToString = "<unbekannt>"
   End Select
End Function

Aufruf

Die Funktion kann man dann z.B. so verwenden:

Public Function DisplayFields(TblName As String)
 
   Dim db  As DAO.Database
   Dim tdf As DAO.TableDef
   Dim fld As DAO.Field
 
   Set db = CurrentDb
   Set tdf = db.TableDefs(TblName)
   For Each fld In tdf.Fields
      Debug.Print Fld.Name, FieldTypeToString(fld.Type), fld.Size
   Next
 
End Function

Siehe auch

  • Hilfe: Type-Eigenschaft, Einstellungen und Rückgabewerte