Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Importing an Excel Spreadsheet into a Table

Posted on 2013-01-30
7
Medium Priority
?
343 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 3
7 Comments
 
LVL 120

Accepted Solution

by:
Rey Obrero (Capricorn1) earned 2000 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 120

Expert Comment

by:Rey Obrero (Capricorn1)
ID: 38836019
that is correct..
0
Microsoft Certification Exam 74-409

Veeam® is happy to provide the Microsoft community with a study guide prepared by MVP and MCT, Orin Thomas. This guide will take you through each of the exam objectives, helping you to prepare for and pass the examination.

 

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 120

Expert Comment

by:Rey Obrero (Capricorn1)
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

Office 365 Training for Admins - 7 Day Trial

Learn how to provision tenants, synchronize on-premise Active Directory, implement Single Sign-On, customize Office deployment, and protect your organization with eDiscovery and DLP policies.  Only from Platform Scholar.

Question has a verified solution.

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

Outlook for dependable use in a very small business   This article is about using the Outlook application (part of Microsoft Office) in a very small business, or for homeowners where dependability and reliability are critical requirements. This …
We live in a world of interfaces like the one in the title picture. VBA also allows to use interfaces which offers a lot of possibilities. This article describes how to use interfaces in VBA and how to work around their bugs.
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…
Visualize your data even better in Access queries. Given a date and a value, this lesson shows how to compare that value with the previous value, calculate the difference, and display a circle if the value is the same, an up triangle if it increased…

705 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