Update or Insert (1 Viewer)

vagelisr

Registered User.
Local time
Today, 16:41
Joined
Apr 28, 2011
Messages
87
Hi to all

I need your help.
I have 2 tables
Material_IU and Material

I want to read all the records in the table material_IU and if the records exist in the table Material perform update else perform insert.

I have to work in access 2003 about 5 years and it is very urgent....

Thanks for your help...
 

Minty

AWF VIP
Local time
Today, 14:41
Joined
Jul 26, 2013
Messages
10,354
Google for a Upsert query !

It needs certain conditions to be met - you can see the full answer here https://stackoverflow.com/questions/6199417/upserting-in-ms-access

An "upsert" is possible, if the tables have a unique key.

This old tip from Smart Access is one of my favourites:

Update and Append Records with One Query

By Alan Biggs

Did you know that you can use an update query in Access to both update and add records at the same time? This is useful if you have two versions of a table, tblOld and tblNew, and you want to integrate the changes from tblNew into tblOld.

Follow these steps:

Create an update query and add the two tables. Join the two tables by dragging the key field of tblNew onto the matching field of tblOld.

Double-click on the relationship and choose the join option that includes all records from tblNew and only those that match from tblOld.

Select all the fields from tblOld and drag them onto the QBE grid.

For each field, in the Update To cell type in tblNew.FieldName, where FieldName matches the field name of tblOld.

Select Query Properties from the View menu and change Unique Records to False. (This switches off the DISTINCTROW option in the SQL view. If you leave this on you'll get only one blank record in your results, but you want one blank record for each new record to be added to tblOld.)

Run the query and you'll see the changes to tblNew are now in tblOld.

This will only add records to tblOld that have been added to tblNew. Records in tblOld that aren't present in tblNew will still remain in tblOld.
 

Users who are viewing this thread

Top Bottom