0

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?

Pᴇʜ
  • 56,719
  • 10
  • 49
  • 73
jasz21
  • 1

2 Answers2

0

Options:

  1. import to an already existing table

  2. run an ALTER TABLE action SQL after import

  3. use an import specification

June7
  • 19,874
  • 8
  • 24
  • 34
0

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
mdialogo
  • 463
  • 8
  • 15