473,387 Members | 3,810 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,387 software developers and data experts.

Update Query Help!

Hi,

I need some help on writing an update query to update "UnitsSold" field in
Products Table whenever I save a transaction. The transaction may contain
several "Subtransactions", one for each product sold in that transaction. I
have a subtransaction table that maintains record of each subtransaction,
with data such as: ProductID, Quantity, TransactionID etc.
The Products table has fields: ProductID, UnitsSold, UnitsOrdered,
UnitCostPrice etc.

What I want is to update UnitsSold for each ProductID in Products table by
adding Quantity field for each subtransaction in Subtransaction table that
has this ProductID.

Currently I have this Query:
UPDATE Products INNER JOIN Subtransactions ON
[Products].[ProductID]=[Subtransactions].[ProductID]
SET Products.UnitsSold =
DSum("Quantity","Subtransactions","Subtransactions .ProductID=[Forms]![Transa
ctions]![Subtransactions Subform].[Form]![ProductID]")
WHERE
((([Subtransactions].[ProductID])=[Forms]![Transactions]![Subtransactions
Subform].Form!ProductID));

The problem with this query is that it only updates the UnitsSold for the
product that is currently "selected" in the Subtransactions Subform.

Can someone suggest how can the query be modified so as to update ALL
products, and not the only one selected?

Thanks in advance.

Kunal.

Nov 12 '05 #1
1 5143
Can I suggest you do not do this?
How will you handle it when a user deletes one of the subform records? What
about if someone changes the quantity from 100 to 10 after you have already
run this update query?

For an alternative way to solve this issue, see:
Inventory Control - Quantity On Hand
at:
http://allenbrowne.com/AppInventory.html

--
Allen Browne - Microsoft MVP. Perth, Western Australia.
Tips for Access users - http://allenbrowne.com/tips.html

"Kunal" <ku*********@motorola.com> wrote in message
news:bj**********@avnika.corp.mot.com...
Hi,

I need some help on writing an update query to update "UnitsSold" field in
Products Table whenever I save a transaction. The transaction may contain
several "Subtransactions", one for each product sold in that transaction. I have a subtransaction table that maintains record of each subtransaction,
with data such as: ProductID, Quantity, TransactionID etc.
The Products table has fields: ProductID, UnitsSold, UnitsOrdered,
UnitCostPrice etc.

What I want is to update UnitsSold for each ProductID in Products table by
adding Quantity field for each subtransaction in Subtransaction table that
has this ProductID.

Currently I have this Query:
UPDATE Products INNER JOIN Subtransactions ON
[Products].[ProductID]=[Subtransactions].[ProductID]
SET Products.UnitsSold =
DSum("Quantity","Subtransactions","Subtransactions .ProductID=[Forms]![Transa ctions]![Subtransactions Subform].[Form]![ProductID]")
WHERE
((([Subtransactions].[ProductID])=[Forms]![Transactions]![Subtransactions
Subform].Form!ProductID));

The problem with this query is that it only updates the UnitsSold for the
product that is currently "selected" in the Subtransactions Subform.

Can someone suggest how can the query be modified so as to update ALL
products, and not the only one selected?

Thanks in advance.

Kunal.

Nov 12 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: Surendra | last post by:
I have this query that I need to use in an Update statement to populate a field in the table by the value of Sq ---------------------------------------------------------------------------- Inline...
2
by: Mike Leahy | last post by:
Hello all, This question is related to updating tables - is there any way to calculate or update the values in a column in a table to the values in a field produced by a query result? An...
10
by: Randy Harris | last post by:
I imported records into a table, later found out that many of them had trailing spaces in one of the fields. If I'd caught it sooner, I could have trimmed the spaces before the import. This...
8
by: Maxi | last post by:
There is a lotto system which picks 21 numbers every day out of 80 numbers. I have a table (name:Lotto) with 22 fields (name:Date,P1,P2....P21) Here is the structure and sample data: ...
7
by: Mark Carlyle via AccessMonster.com | last post by:
I have this update query that I am trying to run. I know the syntax is messed up but do not know how to correct it. Select 'UPDATE', Transactions,'Set = where = ' From "Get Daily Balances" ...
3
by: Shapper | last post by:
Hello, I have created 3 functions to insert, update and delete an Access database record. The Insert and the Delete code are working fine. The update is not. I checked and my database has all...
8
by: rriness | last post by:
I'm getting an inconsistent failure when trying to save data in ADO.Net. I'm using an Access database with a simple query - SELECT StudentID, FirstName, LastName FROM Students - and have no...
3
by: eholz1 | last post by:
Hello PHP programmers. I had a brilliant idea on one of my pages that selects some data from my mysql database. I first set the page up to display some info and an image, just one item, with a...
16
by: ARC | last post by:
Hello all, So I'm knee deep in this import utility program, and am coming up with all sorts of "gotcha's!". 1st off. On a "Find Duplicates Query", does anyone have a good solution for...
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: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
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
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: 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...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

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.