Results 1 to 4 of 4

Thread: primary key.....

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Feb 2002
    Posts
    30

    primary key.....

    i know how to create table and rows and columns of .mdb file in visual basic but how to set a primary key on any field.How is it possible.

  2. #2
    Fanatic Member
    Join Date
    Nov 2001
    Location
    Bangkok
    Posts
    969

    Hi

    First at all I don't use the primary key anymore. It is annoying, hehe.

    Better is in my opinion to create in Access the Indexes that you need and then just activate them in VB. If you use ADO then is it:
    recordset.index ="NameCity" (if you created an index with name and city)

    If you make then recordset.MoveFirst then you are on the first record of this Indexsort.

    With recordset.Seek is it possible to seek then a record. Specially if you have many records is the index good.

    My experience is that with less then 10.000 records is no index needed. Sort and Find is fast enough.

    Franky

  3. #3
    Hyperactive Member
    Join Date
    Jul 2002
    Location
    Canada
    Posts
    455
    Hello Sujaanpals,

    Try this code:

    Private Sub Command1_Click()
    Dim Ws As Workspace
    Dim Db As Database

    If Dir("c:\q.mdb") <> "" Then Kill ("c:\q.mdb")
    Set Ws = DBEngine.Workspaces(0)

    Set Db = Ws.CreateDatabase("c:\q.mdb", dbLangGeneral)
    SqlSel = "Create Table Customer ( Customer Text, Project TEXT CONSTRAINT MyFieldConstraint PRIMARY KEY"
    SqlSel = SqlSel + ", Plant" + " text"
    SqlSel = SqlSel + ");"
    Db.Execute SqlSel
    Db.Close

    End Sub

    Nice regards,

    Michelle.

  4. #4
    Fanatic Member
    Join Date
    Nov 2001
    Location
    Bangkok
    Posts
    969

    Hi

    Be aware that the method from Michelle is very dangerous for existing data, because it recreate always a new EMPTY Table.

    Franky

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