TableDef Object, TableDefs Collection Example (MDB)

The following example creates a new TableDef object, defines a field within it, and appends it to the TableDefs collection of the current database:

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

    ' Return reference to current database.
    Set dbs = CurrentDb
    ' Create new TableDef object.
    Set tdf = dbs.CreateTableDef("Contacts")
    ' Create new Field object.
    Set fld = tdf.CreateField("ContactName", dbText, 30)
    ' Append new objects.
    tdf.Fields.Append fld
    dbs.TableDefs.Append tdf
    Set dbs = Nothing
End Sub