473,395 Members | 1,452 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,395 software developers and data experts.

How to subtract values between two queries if control value is the same (Access 2003)

Firstly: I've a fairly inexperienced access user!

I'm developing a simple stock control database and need to be able to show a total stock for each item.

So far I have two queries, both are grouped by the unique item of stock.

The first query shows how many items of stock we have received. All unique items of stock are always displayed even if there are none in stock.

The second query shows how many items of stock we have issued. The second query only displays unique items of stock where at least 1 has been issued.

I need to subtract the total issued items from the total received items, for each unique stock item. I need to be able to do this even if no items of a stock item have been issued.

E.g. (NULL denotes stock hasn't been issued and therefore does not appear in query 2):

Item Description | Query Value 1 | Query Value 2 | Total

40gb HDD | 20 | 5 | 15
80gb HDD | 3 | NULL | 3

You get the idea :)

Any ideas on the best way to do this without needing to have the issued stock listed as 0 for things which I haven't issued (this would make other reports look messy!)
Jun 25 '10 #1

✓ answered by jimatqsi

Join query 1 to query 2, including all items in query 1 and only those with matching Items in query 2. Add a column "Stock:[Query1Value]-nz([Query2Value],0)"

Note that if you have used the same column name for units in both tables/queries (i.e "Quantity"), you will have to qualify that equation with the table name so it knows which "Quantity" you are talking about, like this:

"Stock:[Query1].[Quantity]-nz([Query2].[Quantity],0)"

NZ converts Nulls to whatever you supply in the second parameter.

Jim

6 7153
jimatqsi
1,271 Expert 1GB
Join query 1 to query 2, including all items in query 1 and only those with matching Items in query 2. Add a column "Stock:[Query1Value]-nz([Query2Value],0)"

Note that if you have used the same column name for units in both tables/queries (i.e "Quantity"), you will have to qualify that equation with the table name so it knows which "Quantity" you are talking about, like this:

"Stock:[Query1].[Quantity]-nz([Query2].[Quantity],0)"

NZ converts Nulls to whatever you supply in the second parameter.

Jim
Jun 25 '10 #2
Hi,


Thanks for that, it works on the calculation side.

I now have a new problem!

I've told the query to group by stock item, so that no matter how many of an item we receive, it only display the item once with the total stock next to it.

E.g.

On the 1st we receive 10 40gb HDD's
On the 15th we receive 10 40gb HDD's.

I'd like it to show:

40gb HDD's | 20

But instead it's showing:

40gb HDD's | 10
40gb HDD's | 10

The attached pictures show how it looks and how it is set up.

Hope someone can help!
Attached Images
File Type: jpg stkdatabase1.jpg (15.5 KB, 488 views)
File Type: jpg stkdatabase2.jpg (14.8 KB, 940 views)
Jun 25 '10 #3
jimatqsi
1,271 Expert 1GB
The pics are too small to read the text, but I assume you are grouping by quantities and you should be summing the quantities. So change "group by" to "Sum" and you should be good to go.

Jim
Jun 25 '10 #4
@jimatqsi
Gaaa!!!

I've done that and it works... Unless I issue the same items of stock on different orders...

E.g.

I have 5 40gb HDD's in stock.
I issue 2 40gb HDD's on order 1
I issue 1 40gb HDD on order 2
The total remaining should be 2 40gb HDD's

However... Access takes it upon itself to multiply the received stock by the number of orders that item was issued on and THEN does the subtraction!

So I end up with 10 in stock (5 * number of orders) then it takes 3 away (the total ordered across all orders)!

Is there a way of stopping this?

I thought I'd got it but, as with many things Microsoft, so close yet so far!
Jun 25 '10 #5
jimatqsi
1,271 Expert 1GB
The first, simplest way is to group by the on hand quantity. Since you are already grouping by item, and the item has only 1 on hand value, it doesn't really change your grouping any, and it solves your problem.

Another is to make a separate query on the sales table only, to Sum all the sold quantities and group by item. That will give you one row for each item, with a sold qty. Then do another query which joins one row from this query with the inventory master (again one row per item) so your final result is only one row per item, with correct sales totals.

Both ways work and there's something to be learned from trying it each way.

Jim
Jun 25 '10 #6
I've got it sorted. I opened the database this morning, deleted the existing queries and re-wrote them and it works as I want it too now!

Thanks for your help :)
Jul 12 '10 #7

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

Similar topics

0
by: Sabine Oebbecke | last post by:
Hi Experts! I have several forms and reports where controls get their values with 'Forms!MainForm!Control' or 'Forms!MainForm!Subform!Control' resp 'Forms!MainForm!Subform.Form!Control' which...
0
by: Patrick Fisher | last post by:
Hello I have just upgraded one of my programs from Acc97 to Acc2003 which was very easy process. The only problem I have found is that any form that has a Tab Control with forms on one or more...
1
by: gazelle04 | last post by:
I want to use the RichTextBox control in access 2003. I can do that in Access 97 but not anymore in 2003 because the Common Dialog Box is now gone in Access 2003. How can I use the RichTextBox to...
1
by: gazelle04 | last post by:
I've been looking for the Common Dialog Control in Access 2003 but I couldn't find it. Usually you can find it in the Insert - Active X controls menu. Does Access 2003 doesn't use Common Dialog...
0
by: gazelle04 | last post by:
How can I make the texts scroll in the RichTextBox control in Access 2003. There is no Vertical Scroll Bar in the property sheet.
2
by: jd2001 | last post by:
I was a VB programmer, but now I am doing lots of VBA programming. I am trying to use the ADO Control on the form, but I can't find it on the control list. Can I use ADO control on Access2003? if...
1
by: RGF | last post by:
Hi, I have a GridView control which is binded to a dataset object, I am able to populate the GridView with the expected data, so that is ok. I enabled the Selection function from the GridView,...
5
by: ServiciosDeCiclismoDelPeru | last post by:
Hi All, I have the expression =IIf(.,., ..) assigned to the ControlSource of a Text Box. This functions correctly in Access 2000 but in Access 2003 the #Name? error is displayed. I don't...
8
Dököll
by: Dököll | last post by:
Hey gang! Below code allows me to search my database though all fields included on the form. Works great. Small issue, when I fetch partial phrases, if they contain an apostrophy, say, "Ferris...
7
by: AkosBeres | last post by:
I’m in the process of setting a sample local Access table called "Fruits" to store data in the following sample fileds: Week Amount Description Version or sequence The data will be loaded into...
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: 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...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
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
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...

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.