473,490 Members | 2,489 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Ms Access advanced calculation query, stock level? :S

36 New Member
Hi :-)

I'm using Ms Access 2003 to create a DB for my school project and I need to accomplish the following:-

* Calculate balances for stock (inclusive of sales and replenishment to stock)

My table (StockDetails):

StockId (PK)
OriginalStock
AmountSold
AmtReceived


I designed a query that says:
SELECT StockDetails.StockId, StockDetails.OriginalStock, StockDetails.AmountSold, StockDetails.AmtReceived, [OriginalStock]-[AmountSold]+[AmountRcd] AS Balance
FROM StockDetails;

However, from this query I'm only able to have it function (calculate) correctly for the first entry, every other entry goes back to :-

*Calculate from the original (OriginalStock) amount e.g. if the OriginalStock is 15 and 1 item was sold then it would be 14 as the Balance BUT 15 still remains as the original stock. So the next time I try to conduct a sale of this item it will once again assume the 15 as the OriginalStock.

Thus I would like to have the Balance to be the same as the OriginalStock amount each time the level is altered either by sale or replenishment.

I've tried designing many queries but none have been successful to accomplish the desirable. Some gave the response 'Circular reference........'

Any assistance rendered to achieve the result desired would be greatly appreciated.

Thanks a mil!
Aug 11 '09 #1
4 7608
ChipR
1,287 Recognized Expert Top Contributor
Your database design is making this difficult for you. To track stock correctly, you should have the items in one table and the sales transactions in another, or split into two. Consider something like this:

tblStockDetails
StockId - Long (pk)
OriginalStock - Long

tblSalesTransaction
StockId - Long (pk) (fk)
SaleDate - Date (pk)
AmountSold - Long
Price(optional)

tblShipment
ShipmentNumber - Long (pk)
StockID - Long (fk)
AmtReceived - Long

Then you have a totals query for each table grouped by StockID, join those with the tblStockDetails and you get your current onhand quantities easily.
Aug 11 '09 #2
student2
36 New Member
Thank a lot ChipR!

I changed the design of my DB to what you've suggested and it works well.
I've created the totals queries for the individual tables and that works well also.

However, I don't think I understand the 'join' aspect of it, because when I try to do it, I get the values duplicating for each StockId. (e.g. if I've received 10 for StockId 1 then I'm seeing that 10 for all StockIds)
Aug 11 '09 #3
ChipR
1,287 Recognized Expert Top Contributor
Great!
Just make sure that you have an Inner Join by having a line between the StockID in each table in your query. Or in the SQL syntax it should say INNER JOIN on ...
Aug 11 '09 #4
student2
36 New Member
Thank you very much ChipR!
Appreciate.
Aug 11 '09 #5

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

Similar topics

3
4216
by: Jason | last post by:
I will explain (or at least try to) first and then give an example after. I need to append a number of rows from several tables into one master table. Unfortunately there are certain columns...
1
1941
by: Cady Steldyn | last post by:
Example: Date | ItemCode | Stock_In_qty | Stock_Out_qty | Bal_qty ------------------------------------------------------------------ 12/09/2003 | A100 | 20 | 0 ...
2
1647
by: Astra | last post by:
Hi All Wondered if you could help me with the below query. I have 1 simple table called STOCKCATS that consists of 2 fields. These fields are called CATID and LEVEL. The contents of this...
4
2873
by: Michael John | last post by:
Dear Oracle Developers, my task is to make up a Oracle View from a Pivot table in MS Access. Given are two tables to join: T_FIRM: FIRM_ABBR VARCHAR2(3 BYTE), FIRM_LONG ...
13
3956
by: royaltiger | last post by:
I am trying to copy the inventory database in Building Access Applications by John L Viescas but when i try to run the database i get an error in the orders form when i click on the allocate...
0
2993
by: Limpor | last post by:
Hello, I am new to learning java, and i am trying to build the class for a calculation card game, unfortunately i can't get the public Card top() and Card takeTop() method in the Stock class. Can...
7
2681
by: helraizer1 | last post by:
Hey, I have a table called TblStock with 10 columns but 3 which need the focus here. These three columns are 'Stock Level', 'Re-order Level' and 'Re-order Quantity'. The Stock level fields...
9
13350
by: longmanm | last post by:
I realise there isn't a direct replacement of countif for excel in access but I am struggling to get aggregate functions to work for me in access 2003 queries. I am creating a stock management db,...
2
2597
by: sazd1 | last post by:
I am using vb express and MsAccess as database. I am trying to write a query for the calculation of Stock. My tables are as under: PId PDate ItemId Description Price Quantity ...
0
7146
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
7183
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...
1
6852
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
7356
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
5448
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
4878
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
4573
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
1389
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
628
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.