Solved

Import only new records from an Excel file into an existing table

Posted on 2016-07-16
3
78 Views
Last Modified: 2016-07-17
Hi Experts

I'm needing to import a number of Excel files (separately) into existing tables in my database using VBA.

I can successfully do this with the DoCmd.TransferSpreadsheet however, I only want to add new records in each table.

As an example, the table "AdvParticipants" has a unique "userid" field and if the value in the column "userid" of the spreadsheet already exists in the field "userid" of this table, then skip it, otherwise import the record. I only need data to the last row and column in the spreadsheet imported.

And if possible, at the time of import, I would like to add 2 other fields which do not exist in the spreadsheet - [ImportDate] = "Now()" and Process Desc] = "Round1".

Any help would be appreciated.

Thanks
darls15
0
Comment
Question by:darls15
3 Comments
 
LVL 39

Assisted Solution

by:als315
als315 earned 250 total points
ID: 41715014
You can link Excel files instead of direct import and import data with query, where you can compare file with existing records and modify any field
0
 
LVL 142

Accepted Solution

by:
Guy Hengel [angelIII / a3] earned 250 total points
ID: 41715025
alternatively, i would suggest to load the excel sheet into Staging Tables, validate the data there, and then load the data to the final tables. easier in the end...
0
 

Author Comment

by:darls15
ID: 41716112
Hi, thank you both for your suggestions. Using staging tables seem to be the way to go for my database. I'll award equal points for both these suggestions as they are both workable solutions. Thanks again :)
0

Featured Post

Backup Your Microsoft Windows Server®

Backup all your Microsoft Windows Server – on-premises, in remote locations, in private and hybrid clouds. Your entire Windows Server will be backed up in one easy step with patented, block-level disk imaging. We achieve RTOs (recovery time objectives) as low as 15 seconds.

Join & Write a Comment

When you are entering numbers in a speadsheet, and don't remember what 6×7 is, you just type “=6*7" instead. It works in every cell! This is not so in Access. To enter the elusive 42 in a text box, you have to find a calculator, and then copy the re…
Describes a method of obtaining an object variable to an already running instance of Microsoft Access so that it can be controlled via automation.
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…
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…

760 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

19 Experts available now in Live!

Get 1:1 Help Now