[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1963
  • Last Modified:

CAnnot add record(s); primary key for table 'table1' not in recordset

I have table1 is a history table which contains fields primarykey, customerid, month, year, and other fields for the period
table2 contains customer info of 'a' given month/year

I want to 'update' table2 information to to table1.  

So

I  created query1, which contains all fields of table1, with criteria month and year set to the month and year I want to update.

I created query2, which has table1 left join with query1.

If query2 is a select query and I include primary of table1, then the query is fine and updatable.

However, if I made query2 an update query then I get the error message 'Cannot add record(s); primary key for table 'table1' not in recordset'.  I can't include primary key for table 'table1' because it's an update query.

Help?
0
jezsun
Asked:
jezsun
1 Solution
 
Bob LambersonSoftware EngineerCommented:
Can you post your queries?


Bob
0
 
harfangCommented:
Maybe there is some confusion...

1) Although I think you got that right: you can run an update query (execute) by double-clicking it or using the [!] button. You can also open an update query *as* select query if you use the normal "open query" button from the left of the toolbar, from design mode.

2) In datasheet view of a LEFT JOIN query, you can do several things: update data, auto-insert data in the right-side table, append new rows to the left-side table, etc. In action queries, you do only one thing at a time.

So:

* make two copies of your query
* in copy one, the UPDATE query, set the join to INNER JOIN, to update information from matching fields.
* in copy two, change to APPEND query and add the criteriy under "query1.keyfield" to Null. This will select only unmatched records, e.g. *new* records.

So you will be able to update in two steps: update matching records and append new records.

Hope this helps
0

Featured Post

Fill in the form and get your FREE NFR key NOW!

Veeam is happy to provide a FREE NFR server license to certified engineers, trainers, and bloggers.  It allows for the non‑production use of Veeam Agent for Microsoft Windows. This license is valid for five workstations and two servers.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now