>

CreateTableDef Method

Applies To

Database Object.

Description

Creates a new TableDef object.

Syntax

Set variable = database.CreateTableDef([name[, attributes[, source[, úconnect]]]])

The CreateTableDef method syntax has these parts.

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.


Remarks

If you omit one or more of the optional parts when you use CreateTableDef, you can use an appropriate assignment statement to set or reset the corresponding property before you append the new object to a collection. After you append the object, you can alter some but not all of its properties. See the individual property topics for more details.

If name refers to an object that is already a member of the collection or you specify an invalid property in the TableDef or Field object you're appending, a trappable error occurs when you use the Append method.

To remove a TableDef object from a collection, use the Delete method on the collection.

See Also

Append Method, Attributes Property, Connect Property, Delete Method, Name Property, TableDef Object.

Example

This example creates a new TableDef object in the Biblio.mdb database.


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).