Solved

Importing an Excel Spreadsheet into a Table

Posted on 2013-01-30
7
325 Views
Last Modified: 2013-01-30
I have a table that has the primary key as a combination of the first name, last name and middle name. From time to time, I import records from a spreadsheet into the table by executing the following command: DoCmd.TransferSpreadsheet acImport, acSpreadsheetTypeExcel9, "File_Name", strflName, True, "".

The problem I am facing is that if there are any records in the spreadsheet that have exactly the same primary key values (first name, last name and middle name) as the record in the table, they will not get inserted since that will cause a duplicate primary key error. This does not happen very often, but it does occur from time to time. What I would like it to do in cases like these is to overwrite the existing record in the table with the new record from the spreadsheet, as I would prefer to have the latest version of a record in the table. How can I get it to do that?
0
Comment
Question by:geeta_m9
  • 4
  • 3
7 Comments
 
LVL 119

Accepted Solution

by:
Rey Obrero earned 500 total points
ID: 38835989
you need to import the excel file into a temp Table.
after importing.. run two queries
1. append query, to append new records
2.update query, to update existing record with the new data from the temp Table
0
 

Author Comment

by:geeta_m9
ID: 38836007
I assume I should make the primary key of the Temp table be exactly the same as the main table?
0
 
LVL 119

Expert Comment

by:Rey Obrero
ID: 38836019
that is correct..
0
Comprehensive Backup Solutions for Microsoft

Acronis protects the complete Microsoft technology stack: Windows Server, Windows PC, laptop and Surface data; Microsoft business applications; Microsoft Hyper-V; Azure VMs; Microsoft Windows Server 2016; Microsoft Exchange 2016 and SQL Server 2016.

 

Author Comment

by:geeta_m9
ID: 38836392
I tried what you suggested and it seems to work. However, it gives me a warning the Microsoft can't append all the records to the table (because of the duplicate records). How do I suppress this warning?
0
 
LVL 119

Expert Comment

by:Rey Obrero
ID: 38836432
revised your append query with a where clause..

should be something like this

Insert into tablex.*
select tableY.*
from tableY
where tableY.id not in(select [id] from tableX)
0
 

Author Comment

by:geeta_m9
ID: 38836908
Ok. This command will also turn off the warnings: DoCmd.SetWarnings False
0
 

Author Closing Comment

by:geeta_m9
ID: 38836911
Thanks.
0

Featured Post

Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

Join & Write a Comment

PaperPort has a feature called the "Send To Bar". It provides a convenient, drag-and-drop interface for using other installed software, such as Microsoft Office. However, this article shows that the latest Office 2016 apps (installed with an Office …
In this article we discuss how to recover the missing Outlook 2011 for Mac data like Emails and Contacts manually.
In Microsoft Access, when working with VBA, learn some techniques for writing readable and easily maintained code.
The viewer will learn how to simulate a series of coin tosses with the rand() function and learn how to make these “tosses” depend on a predetermined probability. Flipping Coins in Excel: Enter =RAND() into cell A2: Recalculate the random variable…

747 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now