>
| Part | Description |
| variable | A variable declared as an object data type TableDef. |
| database | The variable name of the Database object you want to use to create the new TableDef object. |
| name | A String variable that uniquely names the new TableDef object. See the Name property for details on valid TableDef names. |
| attributes | A Long variable that indicates one or more characteristics of the new TableDef object. See the Attributes property for more information. |
| source | A String variable containing the name of a table in an external database that is the original source of the data. The source string becomes the SourceTableName property setting of the new TableDef object. |
| connect | A String variable containing information about the source of an open database, a database used in a pass-through query, or an attached table. See the Connect property for more information on valid connection strings. |
Dim tdfTitleDetail As TableDef, fldComments As Field
Dim dbsBiblio As Database
Set dbsBiblio = DBEngine.Workspaces(0).OpenDatabase("Biblio.mdb")
' Create new TableDef.
Set tdfTitleDetail = dbsBiblio.CreateTableDef("Title Detail")
' Add field to tdfTitleDetail.
Set fldComments = tdfTitleDetail.CreateField("Comments",dbMemo)
tdfTitleDetail.Fields.Append fldComments
' Save TableDef definition by appending it to TableDefs collection.
dbsBiblio.TableDefs.Append tdfTitleDetail
Example (Microsoft Access)
The following example creates a new TableDef object and appends it to the TableDefs collection of the current database.
Sub NewTable()
Dim dbs As Database, tdf As TableDef, fld As Field
' Return Database variable pointing to current database.
Set dbs = CurrentDb
' Return TableDef object variable that points to new table.
Set tdf = dbs.CreateTableDef("Contacts")
' Define new field in table.
Set fld = tdf.CreateField("ContactName", dbText, 40)
' Append Field object to Fields collection of TableDef object.
tdf.Fields.Append fld
' Append TableDef object to TableDefs collection of database.
dbs.TableDefs.Append tdf
End Sub
Example (Microsoft Excel)
See the CreateDatabase method example (Microsoft Excel).