Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

update and insert records

Posted on 2009-05-09
4
Medium Priority
?
227 Views
Last Modified: 2013-11-27
Hello.
I would like to be able to update existing records and insert new records into a main table from another table.

Is this possible using append query to do the inserts and update query to change the data on existing records?

I have been trying to do an append query to append new records into the main table if they don't already exist another table. Then doing an update query to update the existing data in the main table?

How may this be done or is it better doing it with a macro or code

Thanks,
Ivan
0
Comment
Question by:icarey
  • 2
  • 2
4 Comments
 
LVL 143

Expert Comment

by:Guy Hengel [angelIII / a3]
ID: 24343361
you have to do this with 2 queries.
first, the update based on the join for the existing ones, and then insert those that are not yet in the table.
the update should be easy.
the insert requires a select like this one:
select b.*
  from table b
  left outer join a on (a.key = b.key) 
   where a.key is null

Open in new window

0
 
LVL 3

Author Comment

by:icarey
ID: 24343580
thanks angelIII

I have created the query ok but am unable to insert into the table due to field count

Tables STOCK and stock_new
Field names in both
NAME TITLE NAME2

SELECT stock_new.*
FROM stock_new LEFT JOIN STOCK ON stock_new.NAME2 = STOCK.NAME2
WHERE (((STOCK.NAME2) Is Null));

displays the new records

INSERT INTO STOCK(NAME,TITLE,NAME2)
SELECT stock_new.*
FROM stock_new LEFT JOIN STOCK ON stock_new.NAME2 = STOCK.NAME2
WHERE (((STOCK.NAME2) Is Null));

comes up with an error
Number of query values and destination fields are not the same

0
 
LVL 143

Accepted Solution

by:
Guy Hengel [angelIII / a3] earned 2000 total points
ID: 24343616
this will do:
INSERT INTO STOCK(NAME,TITLE,NAME2)
SELECT stock_new.Names2, stock_new.Title, stock_new.Names2
FROM stock_new LEFT JOIN STOCK ON stock_new.NAME2 = STOCK.NAME2
WHERE (((STOCK.NAME2) Is Null));

Open in new window

0
 
LVL 3

Author Closing Comment

by:icarey
ID: 31579754
Thank you angelIII your answer has help me greatly

Ivan
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Traditionally, the method to display pictures in Access forms and reports is to first download them from URLs to a folder, record the path in a table and then let the form or report pull the pictures from that folder. But why not let Windows retr…
If you need a simple but flexible process for maintaining an audit trail of who created, edited, or deleted data from a table, or multiple tables, and you can do all of your work from within a form, this simple Audit Log will work for you.
In Microsoft Access, learn different ways of passing a string value within a string argument. Also learn what a “Type Mis-match” error is about.
In Microsoft Access, when working with VBA, learn some techniques for writing readable and easily maintained code.
Suggested Courses

886 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