Results 1 to 2 of 2

Thread: primary key

  1. #1

    Thread Starter
    New Member
    Join Date
    Apr 1999
    Posts
    1

    Post

    How do I make my field to a primary key?

    here is my code:

    Dim myDataBase As Database
    Dim myTable As TableDef
    Dim myField As field

    Set myDataBase = OpenDatabase("c:\Data.mdb")
    Set myTable = myDataBase.CreateTableDef("table")
    'this the field I want to be the primary key
    Set myField = myTable.CreateField("ID", dbLong)

    myTable.Fields.Append myField
    myDataBase.TableDefs.Append myTable

    Thanks
    Xavier

    ------------------

  2. #2
    New Member
    Join Date
    Jan 1999
    Location
    Cleveland,Ohio,USA
    Posts
    6

    Post

    You can try this:

    Dim td As TableDef
    Dim idxNew As Index

    Set td = db.CreateTableDef("MyTable")
    With td
    .Fields.Append .CreateField("ID", dbLong)
    .Fields.Append ..................
    End With
    db.TableDefs.Append td
    With td
    ' Create and append a new Index object to the
    ' Indexes collection of the new TableDef object.
    Set idxNew = .CreateIndex("PrimaryKey")
    idxNew.Fields.Append idxNew.CreateField("ID")
    idxNew.Primary = True
    .Indexes.Append idxNew
    End With

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width