VBA Tipp: Jet-Feldtypen als Zeichenfolge darstellen

Aus DBWiki
Wechseln zu: Navigation, Suche

Problem

Ich möchte die Feldtypen 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 dbMemo: FieldTypeToString = "Memo"
  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, Tbl As DAO.TableDef, Fld As DAO.Field
  Set DB = CurrentDb
  Set Tbl = DB.TableDefs(TblName)
  For Each Fld In Tbl.Fields
    Debug.Print Fld.Name, FieldTypeToString(Fld.Type), Fld.Size
  Next Fld
End Function

Siehe auch

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