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 TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Import and update table

Status
Not open for further replies.
Sep 7, 2009
29
US
I have a macro that calls import queries to import a table from an offline computer to network table database. I would like the macro to update the data in the network table database. It is overwriting the data in the network table database. How do I fix this?
 
I tried an append query. It creates duplicates. How do perform an update query?
 
If it is cumulative and immutable data, you could append the values that are not there Not IN(<list/sub query>).

You could also delete the values and then append.

You can also join the destination table to the temp table and update all values including the join columns to the import table. Be sure to use an outer join from the import table to ensure it will "update" the missing values. In this scenario I try to use criteria to eliminate things that don't need updated. This may be the slowest performance wise.
 
You only append records from your import that aren't in your production table. You only update records that require updating. This can sometimes be performed with a single query but might be easier with two queries.

Duane
Hook'D on Access
MS Access MVP
 
A generic way:
UPDATE yourTable AS O RIGHT JOIN yourNewTable AS N ON O.PrimaryKey = N.PrimaryKey
SET O.PrimaryKey = N.PrimaryKey, O.SomeField = N.SomeField, O.AnotherField = N.AnotherField

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
A specific example of how to do it reuires knowing the columns/fields of the data and some knowledge about what identifies a record as unique all of which you would need to provide.

But if you had

People
ID Name

Your query might look like...

Code:
Insert Into People (ID, Name)
Select ID, Name
From Import
Where Import.ID Not IN(Select ID From People)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top