Count Property Example (MDB)

The following example prints the names and total number of fields in an Orders table:

Sub CountFields()
    Dim dbs As Database, tdf As TableDef
    Dim fld As Field

    ' Return reference to current database.
    Set dbs = CurrentDb
    ' Return reference to Orders table.
    Set tdf = dbs.TableDefs!Orders
    ' Count fields in Fields collection of TableDef object.
    Debug.Print tdf.Fields.Count
    ' List names of all fields.
    For Each fld In tdf.Fields
        Debug.Print fld.Name
    Next fld
    Set dbs = Nothing
End Sub