Results 1 to 4 of 4

Thread: MS Access, primary key

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Jul 2002
    Location
    Canada
    Posts
    455

    Post

    Hello VB users,

    MS Access problem.

    I am still searching to create a primary key for my field in a table.
    In sql there is a possibility.

    Can someone complete the next code for creating a primary key for the field "NewField"?

    Set Ws = DBEngine.Workspaces(0)
    Set Db = Ws.CreateDatabase("c:\q.mdb", dbLangGeneral)
    Dim tdfNew As TableDef

    Set tdfNew = Db.CreateTableDef("newTable")

    tdfNew.Fields.Append tdfNew.CreateField("NewField", dbText)

    Db.TableDefs.Append tdfNew
    Db.Close

    Nice regards,

    michelle.

  2. #2
    Lively Member
    Join Date
    Jul 1999
    Posts
    78

    Post Elaborate?

    I'm not sure what you're trying to acheive here. . .

    You have an MS Access database, and you require a Primary Key. . . ok, you could just insert one into the table, and select it Indexed, No Duplicates in the properties.

    Please elaborate.

  3. #3
    Frenzied Member
    Join Date
    Aug 1999
    Location
    Santa Clara, Ca , 95058
    Posts
    1,105

    Post

    It looks like Michelle wants to be able to create a primary key on the fly.

    Execute the following SQL (against a jet database), before you issue the db.close:

    db.Execute "Alter table newtable add constraint pkey primary key (newfield);"

  4. #4

    Thread Starter
    Hyperactive Member
    Join Date
    Jul 2002
    Location
    Canada
    Posts
    455

    Post MS Access, primary key

    Hello JohnAtWork & JHausmann,

    Thanks for your tips! I will use them.

    michelle.

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