Solved

Import excel data into Access table

Posted on 2013-05-28
4
674 Views
Last Modified: 2013-05-29
Very similar questions have already been asked, but the difference I can't find an answer to is, I want to import excel data into an existing table, but to add extra fields to the records already there, not to add extra records.

For example, in my Access table 'Recruits', I have ID's A1, A2, A3, A4 & lots of data associated with them.  But we forgot to put some fields in when we created the table, & now have that extra data in an Excel spreadsheet, which I've imported into a new Access table.  This new table 'Import Data' might have records A2 & A4 & I want to the extra data I have for them to add to their records in the Recruits, not create new records.  

I found this thread about writing an Append query
http://www.experts-exchange.com/Database/Miscellaneous/Q_21957519.html, which included suggested code:

INSERT INTO tblUser ( UserID, UserName, Category, Admin, Custodian )
SELECT Userupdate.UserID, Userupdate.Username, Userupdate.Category, Userupdate.Admin, Userupdate.Custodian
FROM Userupdate LEFT JOIN tblUser ON Userupdate.userID = tbluser.UserID
WHERE (((tblUser.UserID) Is Null));
 
But when I tried to convert that to my situation (change field & table names & left off the WHERE statement), it added extra records with IDs A2, A4, so I have two A2 & two A4 records, rather than one record of each with new fields on them.  I'm guessing an Append query is the way to go, its just a matter of telling it to add fields to existing records rather than add new records.  The ID's A2, A4 etc are not the keys of the records, there can be duplicates, but I don't want there to be).

Can anyone help refine the query?
Many thanks
0
Comment
Question by:matavai
  • 2
4 Comments
 
LVL 12

Accepted Solution

by:
duttcom earned 500 total points
ID: 39203534
An append query is specifically for adding (appending) records, not for updating existing ones.

You need to use an update query - http://office.microsoft.com/en-au/access-help/update-data-by-using-a-query-HA010076527.aspx for examples of how to create an update query.

You should also create the new fields in the table before you run the query because the update query will need to reference the additional field names.
0
 
LVL 17

Expert Comment

by:Kent Dyer
ID: 39203540
Have you taken into account that USERID is a UNIQUE INDEXed value?

For example you have the following INSERT Statement:
INSERT INTO tblUser ( UserID, UserName, Category, Admin, Custodian )
SELECT Userupdate.UserID, Userupdate.Username, Userupdate.Category, Userupdate.Admin, Userupdate.Custodian
FROM Userupdate LEFT JOIN tblUser ON Userupdate.userID = tbluser.UserID
WHERE (((tblUser.UserID) Is Null));

Open in new window


I think you need to do something like (I would be willing to bet your UserID - is an Identity Seed with an incrementing value.  In other words, an "auto-incrementing" indexed value.  You probably cannot re-use that.  You may need to create your own id for the table to match against Excel.):
INSERT INTO tblUser ( UserName, Category, Admin, Custodian )
SELECT Userupdate.UserID, Userupdate.Username, Userupdate.Category, Userupdate.Admin, Userupdate.Custodian
FROM Userupdate LEFT JOIN tblUser ON Userupdate.userID = tbluser.UserID
WHERE (((tblUser.UserID) Is Null));

Open in new window


HTH,

Kent
0
 
LVL 12

Expert Comment

by:duttcom
ID: 39203555
Auto incrementing or not, if you use an insert query, you will insert records, not insert new fields to existing ones. Only an update query can do that when the new fields are already in the table.
0
 

Author Comment

by:matavai
ID: 39206139
D'oh!  Once you start with the right kind of query, it makes things quite simple.  That's what I get for expecting Access to always make things more complicated than they need to be.
Thanks
0

Featured Post

Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
AWS RDS Backups? 3 42
Trying to open FORM in specific record !! 6 46
Access 2010 Compatibility With  Access 2010 Runtime 22 34
combo box query 6 8
I annotated my article on ransomware somewhat extensively, but I keep adding new references and wanted to put a link to the reference library.  Despite all the reference tools I have on hand, it was not easy to find a way to do this easily. I finall…
When table data gets too large to manage or queries take too long to execute the solution is often to buy bigger hardware or assign more CPUs and memory resources to the machine to solve the problem. However, the best, cheapest and most effective so…
Familiarize people with the process of retrieving data from SQL Server using an Access pass-thru query. Microsoft Access is a very powerful client/server development tool. One of the ways that you can retrieve data from a SQL Server is by using a pa…
What’s inside an Access Desktop Database. Will look at the basic interface, Navigation Pane (Database Container), Tables, Queries, Forms, Report, Macro’s, and VBA code.

831 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question