We help IT Professionals succeed at work.

Append values to Access table from excel with ID autogenerated

samsri25 asked
I have a access database with some tables which get updated daily with some values. I need the tables to have a ID field which is autogenerated when the other values of the table are imported from excel. I want to automate all by keeping a button and writing a VBA code. Right now I have a form which imports the value into the table, but it just imports the exact value which I have . I also need a extra column of ID that has to be auto generated when I import. Please help me.

Excel Sheet Sample:

ProductName | ProductValue

ABC | 76

SDF | 87


ID|ProductName| Product Value



Excel sheet updates each date with new value and it has to be put to the access db with ID automatically incremented.
Watch Question

James ElliottManaging Director

You need to create a table in your Access DB that has ID (Autonumber) as the first field, then follow it with all of the fields from your spreadsheet.

You then need to append to this table when importing.


I am not sure how it can be done in VB. So is there any code which can allow me to do it? I am able to append it while i manually import the data from excel when I use the tab "EXTERNAL DATA". I want to create a form with a button. On click of the button the value should be imported.
Managing Director
What level of VBA understanding do you have?

The link shows how to connect to a DB and run an Insert statement. You'll have to build your own SQL string by looping through the records you want to insert.


James ElliottManaging Director

You might consider adding your Excel file as a linked table and then using your button in Excel to simply trigger a pre-defined append query in Access. This would probably be cleaner.