473,385 Members | 1,409 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

Use UNION query as record source for UPDATE query

97 Expert
I have a situation where I need to record scrap quantities for parts that we sell and parts that are supplied, in a single table. I have a UNION query that combines the part numbers successfully, allowing the user to select from a combo box without knowing whether the part is supplied or manufactured. I need to provide a DEFAULT value for cost (which, if changed later would not be wrong). To do this, I would like to pull the price from the results of the combined UNION recordset
.
The AfterUpdate Event of the [part number] combo box contains an action query.
Expand|Select|Wrap|Line Numbers
  1. sql = "UPDATE [Internal Rejections Table] INNER JOIN [qryComponent_price] ON " & _
  2.           "([Internal Rejections Table].[Part No] = [qryComponent_price].part_no) " & _
  3.           "SET [Internal Rejections Table].Price = [qryComponent_price].price " & _
  4.           "WHERE (([Internal Rejections Table].ID)=" & Me.ID.Value & ");"
  5.  
[qryComponent_price] is the UNION query
[Internal Rejections Table] is the underlying table my form is based on
Me.ID.Value is the Autonumber of the current record
The current record is saved before running the action query.

The VBA code produces the error: Too few parameters. Expected 1.
When run directly in a query window: Operation must use an updateable query.

These errors point me to believe that my UNION query is not updateable, and is rendering my table read only, in this instance.

Is there another way to achieve my goal in a single step?

(I have considered creating a temporary table, but that feels excessive, alternatively I could run a separate query from each table (supply and manufacture) and handle an empty record set, again overkill).
May 7 '07 #1
8 10758
Rabbit
12,516 Expert Mod 8TB
Try DLookup instead of an INNER JOIN.
May 7 '07 #2
kepston
97 Expert
Try DLookup instead of an INNER JOIN.
Thanks Rabbit, that worked a treat.
Dlookup is a new one on me! I will remember that for future, in fact I may be able to improve some previous projects too.

Cheers!
May 8 '07 #3
Rabbit
12,516 Expert Mod 8TB
Not a problem.
May 8 '07 #4
NeoPa
32,556 Expert Mod 16PB
Be very careful of using DLookup() (or any other Domain Aggregate functions) from within SQL. The performance hit can be extreme (Forget IIf() etc - DLookup executes a query within each record of the query). In some cases it can be the only way to achieve a result. In others, performance is so not an issue that it won't matter.
Without seeing the SQL of the UNION query it's hard to produce a version that would work without the DLookup (and sometimes Access can be VERY restrictive about what it allows the SQL to do), so if performance is no issue, use the DLookup for this one.
I would strongly recommend against considering it for general purpose usage though.
May 8 '07 #5
kepston
97 Expert
Be very careful of using DLookup() (or any other Domain Aggregate functions) from within SQL. The performance hit can be extreme (Forget IIf() etc - DLookup executes a query within each record of the query). In some cases it can be the only way to achieve a result. In others, performance is so not an issue that it won't matter.
Without seeing the SQL of the UNION query it's hard to produce a version that would work without the DLookup (and sometimes Access can be VERY restrictive about what it allows the SQL to do), so if performance is no issue, use the DLookup for this one.
I would strongly recommend against considering it for general purpose usage though.
I'll bear that in mind.
In this instance I required a single value, which I extracted using DLookup into a variable, and was then able to add the variable to the SQL code. This produced the correct result in less than a second, barely noticeable to the user.

The complex part of the UNION has three tables, two INNER JOINs and a GROUP BY, with a reference to the current record on the form.
I am assuming it is the aggregate that caused my nonupdateable recordset.

Thanks for your wisdom.
May 9 '07 #6
NeoPa
32,556 Expert Mod 16PB
I'll bear that in mind.
In this instance I required a single value, which I extracted using DLookup into a variable, and was then able to add the variable to the SQL code. This produced the correct result in less than a second, barely noticeable to the user.
Certainly a good reason for not worrying about performance.
The complex part of the UNION has three tables, two INNER JOINs and a GROUP BY, with a reference to the current record on the form.
I am assuming it is the aggregate that caused my nonupdateable recordset.
I'm pretty sure that any UNION query would be treated as non-updatable in Access, regardless of complexity.
Thanks for your wisdom.
Nice. I like that. Thank you for the compliment, and I'm glad you got an answer that works for you.
May 11 '07 #7
I have a problem with Access Forms. The record source of my Form is a UNION query on 2 tables.

Now, when I try to update any of the fileds on the Forms I cannot. I could do updates when I had record source query as just a SELECT on 1 table.

There might be something very stupid that I am missing. Please let me know if anybody has any suggestions.

Thanks,
Heeral
Oct 25 '07 #8
NeoPa
32,556 Expert Mod 16PB
If you read through the post just before your one (#7), you will see :
I'm pretty sure that any UNION query would be treated as non-updatable in Access, regardless of complexity.
Obviously (I think), any form built on a non-updatable query would not be able to update the data.
Does this make sense?
Oct 26 '07 #9

Sign in to post your reply or Sign up for a free account.

Similar topics

10
by: KENNY L. CHEN | last post by:
Dear experts, I have two tables in my Oracle 8i database: TEST (COL1,COl2,REC_NO) and TEST1 (COL1,COL2,REC_NO). Both tables are unique-indexed on (COL1,COL2,REC_NO). I think the following...
6
by: Eugene | last post by:
Summary: ---------- Updates against UNION ALL view does't do branch elimination, but rather reads all the branches (partitions). The case scenario(DB2 V8.1.4a ESE, AIX 5.2):...
3
by: Dalan | last post by:
From reading Access 97 help text, it seems that to do what I need to do will require a Union Query. As this would be my first, I think I might require a little guidance. I have two tables with...
2
by: Enterprise | last post by:
Hi, Here is my code for the Union query "Table union Table union Table ;" The tables are actually queries themselves. I made a form for the query, but when I try to update the...
5
by: Lyn | last post by:
This one is difficult to explain, so I will cut it down to the basics. I have a major table 'tblA' which has an autonum field 'ID-A' as primary key (of no significance to users). 'tblA' contains...
9
by: Jeremy | last post by:
I have a situation where i am trying to run two query's and retrieve one record from each query, then using Union combine them into one recordset. The First Query is strait forward and should just...
1
by: bgreenspan | last post by:
Hi Everyone, I'm back for some more expert help. Here's what I am doing and what I tried. My database has entries with Contract Names and Expiry Dates, among other fields. I have a form...
6
by: jmarcrum | last post by:
Hi! I have created a Union Query in ACCESS 2003, that combines 130 records from one query (Extra Foreman Radios) and 250 records from another query (Forman Main Radios). I have created a...
13
tuxalot
by: tuxalot | last post by:
I have a listbox with a row source using a union query: SELECT .ReportID, .ReportName, .ReportCaption, .ReportCriteriaFlags, .ReportRemote FROM ORDER BY .ReportCaption; The union query sql: TABLE...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.