Add auto value to Access table

124 Views Asked by At

I've an import from Excel to Access. It works pretty well. My only problem is that after the import there is no column with auto value (primary key).

This is my import:

Private Sub Befehl1_Click()
    DoCmd.TransferSpreadsheet acImport, 10, _
       "Tabelle1", "C:\Users\u054535\Desktop\Mappe1.xlsx", True, "Tabelle2!A1:H13"
End Sub

Does somebody know how to add a column with an auto value to the import? Is it even possible?

2

There are 2 best solutions below

0
June7 On

Options:

  1. import to an already existing table

  2. run an ALTER TABLE action SQL after import

  3. use an import specification

0
mdialogo On

Try this:

Private Sub Befehl1_Click()
    DoCmd.TransferSpreadsheet acImport, 10, _
       "Tabelle1", "C:\Users\u054535\Desktop\Mappe1.xlsx", True, "Tabelle2!A1:H13"

    'Add an AutoNumber column
    CurrentDb.Execute "ALTER TABLE Tabelle1 ADD COLUMN ID COUNTER"
End Sub