• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 226
  • Last Modified:

Append values to Access table from excel with ID autogenerated

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

DATABASE TABLE

ID|ProductName| Product Value

1|ABC|76

2|SDF|87

Excel sheet updates each date with new value and it has to be put to the access db with ID automatically incremented.
0
samsri25
Asked:
samsri25
  • 3
1 Solution
 
James ElliottManaging DirectorCommented:
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.
0
 
samsri25Author Commented:
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.
0
 
James ElliottManaging DirectorCommented:
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.

http://stackoverflow.com/questions/17919696/ado-in-excel-inserting-records-into-access-database

Rgds
0
 
James ElliottManaging DirectorCommented:
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.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Ultimate Tool Kit for Technology Solution Provider

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy now.

  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now