Creating an Index in a Table

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • acoppini
    New Member
    • Jun 2010
    • 8

    Creating an Index in a Table

    Hi - I am trying to create a unique index in an existing table that I will be able to use later to update records. I have the code below. The index Ind field is being created in the table TempAPT but it is not populating with an index. A simple index starting at 1 and growing at an increment of 1 for each row will suffice. What am I doing wrong? This is in VBA Access 2003. Thanks

    Code:
    Public Sub addColAPT()
    DoCmd.SetWarnings False
    
    strSql = "ALTER TABLE TempAPT ADD COLUMN Ind DOUBLE"
    CurrentProject.Connection.Execute strSql
    
    strSql = "CREATE INDEX Ind ON TempAPT(Ind)"
    CurrentProject.Connection.Execute strSql
    
    DoCmd.SetWarnings True
    
    End Sub
  • acoppini
    New Member
    • Jun 2010
    • 8

    #2
    Figured it out - need to use autoincrement as field type:

    Code:
    strSql = "ALTER TABLE TempAPT ADD COLUMN Ind AUTOINCREMENT"
    CurrentProject.Connection.Execute strSql

    Comment

    Working...