Home > Mobile >  MS Access SQL Update Linked table column based on query
MS Access SQL Update Linked table column based on query

Time:12-11

I have a linked table where I need to update a column within an existing row

when I (programmatically) execute an update query referencing a select query it doesn't work but if I execute the same query referencing a table I filled with the query it DOES work. Examples below

I can't find why this is. I made an Access Update query using the Select query and it popped the error "Operation must use an updateable query". I looked that up and got mixed explanations. Does anyone have insight on this? Are there special rules regarding updating a linked table by referencing a select query?

UPDATE Table1, Query1 
SET Table1.Filename = Query1.Filename 
WHERE (Table1.Client = Query1.Client AND Table1.Id = Query1.Id);

UPDATE Table1, Table2 
SET Table1.Filename = Table2.Filename 
WHERE (Table1.Client = Table2.Client AND Table1.Id = Table2.Id);

CodePudding user response:

There is a long list of things that need to be true for a query to be updateable. The basic idea being that all of the data in the query must cleanly map to one real object, nothing calculated at display time.

The primary key IDs must be unique and clearly defined in all the tables in the query.

Alan Browne published a list that should contain the things you need to look for.

"

Why is my query read-only?

If you cannot edit the data in a query, this list may help you identify why it is not updatable:

  • It has a GROUP BY clause. A Totals query is always read-only.

  • It has a TRANSFORM clause. A Crosstab query is always read-only.

  • It uses First(), Sum(), Max(), Count(), etc. in the SELECT clause. Queries that aggregate records are read-only.

  • It contains a DISTINCT predicate. Set Unique Values to No in the query's Properties.

  • It involves a UNION. Union queries are always read-only.

  • It has a subquery in the SELECT clause. Uncheck the Show box under your subquery, or use a domain aggregation function instead.

  • It uses JOINs of different directions on multiple tables in the FROM clause. Remove some tables.

  • The fields in a JOIN are not indexed correctly: there is no primary key or unique index on the JOINed fields.

  • The query's Recordset Type property is Snapshot. Set Recordset Type to "Dynaset" in the query's Properties.

  • The query is based on another query that is read-only (stacked query.)

  • Your permissions are read-only (Access security.)

  • The database is opened read-only, or the file attributes are read-only, or the database is on read-only media (e.g. CD-ROM, network drive without write privileges.)

  • The query calls a VBA function, but the database is not in a trusted location so the code cannot run. (See the yellow box at the top of this Access 2007 page.)

  • The fields that the query outputs are Calcluated fields (Access 2010.)

"

  • Related