Solved

Importing an Excel Spreadsheet into a Table

Posted on 2013-01-30
7
327 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
U.S. Department of Agriculture and Acronis Access

With the new era of mobile computing, smartphones and tablets, wireless communications and cloud services, the USDA sought to take advantage of a mobilized workforce and the blurring lines between personal and corporate computing resources.

 

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Microsoft Edge, Outlook OWA 7 45
Sub Reports 8 23
TSQL DateADD update Question 4 31
MS Access 2010 : hyperlink to picture in report doesn't show picture 2 17
Deploying a Microsoft Access application in a Citrix environment is not difficult but takes a few steps. However, Citrix system people are often of little help, as they typically know next to nothing about Access. The script provided here will take …
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 Microsoft Access, when working with VBA, learn some techniques for writing readable and easily maintained code.
The view will learn how to download and install SIMTOOLS and FORMLIST into Excel, how to use SIMTOOLS to generate a Monte Carlo simulation of 30 sales calls, and how to calculate the conditional probability based on the results of the Monte Carlo …

861 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

22 Experts available now in Live!

Get 1:1 Help Now