• create index column on new table

    Author
    Topic
    #463478

    still working on it, but i have this:

    [codebox] strSQL = “DELETE FROM ;”
    DoCmd.RunSQL strSQL

    strSQL = “SELECT INTO ” & _
    ” FROM ” & _
    ” WHERE ;”

    DoCmd.RunSQL strSQL <– this works fine, new data appears

    Dim dbs As Database
    Dim tdfRUGs As TableDef
    Dim idxID As Index

    Set dbs = CurrentDb
    Set tdfRUGs = dbs!RUGs

    With tdfRUGs
    Set idxID = .CreateIndex("ID")
    End With

    Indexes.Append idxID <– says 'object required'

    [/codebox]

    I tried setting up the new table with an ID column (autonumber, index no dupes) and re-did the delete statement to clear all columns except Mr. ID but the new table runs without keeping that column. which is fine, i want to add the id column after the fact. Just not quite sure how to do it…

    TIA

    Viewing 2 reply threads
    Author
    Replies
    • #1183349

      still working on it, but i have this:

      [codebox] strSQL = “DELETE FROM ;”
      DoCmd.RunSQL strSQL

      strSQL = “SELECT INTO ” & _
      ” FROM ” & _
      ” WHERE ;”

      DoCmd.RunSQL strSQL <– this works fine, new data appears

      Dim dbs As Database
      Dim tdfRUGs As TableDef
      Dim idxID As Index

      Set dbs = CurrentDb
      Set tdfRUGs = dbs!RUGs

      With tdfRUGs
      Set idxID = .CreateIndex("ID")
      End With

      Indexes.Append idxID <– says 'object required'

      [/codebox]

      I tried setting up the new table with an ID column (autonumber, index no dupes) and re-did the delete statement to clear all columns except Mr. ID but the new table runs without keeping that column. which is fine, i want to add the id column after the fact. Just not quite sure how to do it…

      TIA

      The indexes are not referencing any objects

      Try putting it inside the With with a . To apply it to the tabledef

      Code:
      		With tdfRUGs
      			Set idxID = .CreateIndex("ID")
      			idxID.Fields.Append  idxID.CreateField("ID")
      			.Indexes.Append idxID	  '<-- says 'object required'
      		End With
    • #1183350

      Found an even simpler method:

      Dim db As DAO.Database
      Set db = CurrentDb

      strSQL = “ALTER TABLE RUGs ADD [ID] COUNTER;”
      db.Execute strSQL

    • #1183361

      still working on it, but i have this:

      [codebox] strSQL = “DELETE FROM ;”
      DoCmd.RunSQL strSQL

      strSQL = “SELECT INTO ” & _
      ” FROM ” & _
      ” WHERE ;”

      DoCmd.RunSQL strSQL <– this works fine, new data appears

      Dim dbs As Database
      Dim tdfRUGs As TableDef
      Dim idxID As Index

      Set dbs = CurrentDb
      Set tdfRUGs = dbs!RUGs

      With tdfRUGs
      Set idxID = .CreateIndex("ID")
      End With

      Indexes.Append idxID <– says 'object required'

      [/codebox]

      I tried setting up the new table with an ID column (autonumber, index no dupes) and re-did the delete statement to clear all columns except Mr. ID but the new table runs without keeping that column. which is fine, i want to add the id column after the fact. Just not quite sure how to do it…

      TIA

      Do you have to reate this table every time you run this code?

      If so why not change it to an Append query instead?

    Viewing 2 reply threads
    Reply To: create index column on new table

    You can use BBCodes to format your content.
    Your account can't use all available BBCodes, they will be stripped before saving.

    Your information: