Primary Property Example (Professional Edition Only)

The example creates a new Table and primary key Index, then adds it to the TableDefs collection of a Database.

Dim Db As Database, Tb As New TableDef, Idx As New Index
Dim Fd1 As New Field, Fd2 As New Field
Set Db = OpenDatabase("BIBLIO.MDB")   ' Open the Database.
Tb.Name = "Book Types"                ' Set new Table property.
Fd1.Name = "TypeNum"                  ' Set Fd1 Field properties.
Fd1.Type = 4
Tb.Fields.Append Fd1                  ' Add Fd1 Field to TableDef.
Fd2.Name = "Type"                     ' Set Fd2 Field properties.
Fd2.Type = 10
Fd2.Size = 15
Tb.Fields.Append Fd2                  ' Add Fd2 Field to TableDef.
Idx.Name = "PrimaryKey"               ' Set properties in new Index.
Idx.Unique = True
Idx.Primary = True
Idx.Fields = "TypeNum"
Tb.Indexes.Append Idx                 ' Add Index to TableDef.
Db.TableDefs.Append Tb                ' Add TableDef to Database.