Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Overwriting records when importing data 1

Status
Not open for further replies.

JimmyDix

MIS
Feb 9, 1999
13
NZ
I have a database that uses a VBA module to import comma delimited data into a table. I want this data to overwrite what is in the table if a given field is the same. Is there a way to do this?
 
Hi,<br>
<br>
I would first import text file to temporary table (safe!) and then delete the old records and then insert records to target table:<br>
<br>
Something like this:<br>
<br>
DELETE TargetTable.Field1<br>
FROM TargetTable INNER JOIN TempTable ON TargetTable.Field1 = TempTable.Field1<br>
WHERE (((TargetTable.Field1)=[TempTable]![Field1]));<br>
<br>
And:<br>
<br>
INSERT INTO TargetTable ( Field1, Field2, Field3 )<br>
SELECT TempTable.Field1, TempTable.Field2, TempTable.Field3<br>
FROM TempTable;<br>
<br>
You can write these queries as modules or macros and run them without warnings (DoCmd.SetWarnings False)<br>
<br>
Good luck,<br>
Al
 
Didn't quite work...had to use<br>
<br>
DoCmd.RunSQL "DELETE * " & _<br>
"FROM DRAWING " & _<br>
"WHERE DRAWING.[Drawing Number] IN " & _<br>
" (SELECT [Drawing Number]" & _<br>
" FROM TempData); ", -1<br>
<br>
instead. Thanks for the help!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top