473,763 Members | 7,622 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Query Calculation Field Criteria Not Followed

klarae99
85 New Member
In Access 2003 I am creating an Inventory Database from scratch. There are two tables (tblProductInfo rmation and tblSubProducts) that I am trying to use in a queary to determine the number of Items in Stock. The SubProducts table is linked to the Product Information table by Item # (and the information is added and viewed as a form Product Information with a Sub Form Sub Products)

I have a form (frmInventoryLo cation) where a location is selected for the Queary, the queary also has criteria to return all locations if no location is choosen.

There is a calculation field in the queary that I am using to calculate the number in stock by subtracting the # Sold from the # recieved (both fields in the SubProducts table). This calculation works fine. However, I want to limit my list to those enteries that have inventory in stock (AKA In Stock > 0) I have tried adding the >0 criteria to the calculated field but the queary still returns all results, even those with no stock.

I have managed to get around this by creating a second queary (QryInventoryLo cation) that has all the fields from the first queary (QryInventory) and the Criteria of >0 for the In Stock field. This works but requires that I have two quearys to do something that I think I should be able to accomplish in one. Does anyone have any ideas to fix my first queary to 'see' the >0 criteria?
Oct 1 '07
23 2921
klarae99
85 New Member
Hello Scott,

This is not going away easily.

I moved the iff clause into the sum clause like you suggested and am now getting a different set of messages when I click run. First I am getting two dialoge boxes, the first asking for tblSubformProdu cts!#Recieved and the second asking for #Sold. (I also get one asking for location but I know that is because I am running in without the form for input.) If I leave the text boxes blank I get the following error message:

This expression is typed incorrectly, or it is too complex to be evaluated. For example, a numeric expression may contain too many complicated elements. Try simplifying the expression by assigning parts of the expression to variables.

If I enter 1 for the #Recieved and 0 for the #Sold The queary will run but it does not give me the correct In Stock amount, and it also does not give me an answer of 1.

Could this error be because I am using the groupby Sum feature on the # Recieved and #Sold? My reasoning for doing this was to get only one listing per item per location but if it is causing things to be more complicated than they should be maybe there is a different way I could obtain the same result?

Sorry to be such a pain, I had thought that this would be an easier fix. I appreciate all the time you have dedicated to my question.
Oct 2 '07 #11
Scott Price
1,384 Recognized Expert Top Contributor
Again, not a problem! Happy to help out...

How about pasting in the sql you have now; then I'll set this up in my test database and get back to you.

Regards,
Scott
Oct 2 '07 #12
Scott Price
1,384 Recognized Expert Top Contributor
Ok, I put this into my test database and came up with this SQL. This is only using one table: tblSubformProdu cts. It returns one value for each productID and eliminates products that have a balance of 0 in stock...

Expand|Select|Wrap|Line Numbers
  1. SELECT DISTINCTROW tblSubformProducts.ProductID, Sum([tblSubformProducts].[#Recieved]-[tblSubFormProducts].[#Sold]) AS [In Stock]
  2. FROM tblSubformProducts
  3. GROUP BY tblSubformProducts.ProductID
  4. HAVING (((Sum([tblSubformProducts].[#Recieved]-[tblSubFormProducts].[#Sold]))<>0));
  5.  
It could also be useful to you turning this around, to find out which product is sold out, eh? To do that just change the <>0 to =0...

Regards,
Scott
Oct 2 '07 #13
klarae99
85 New Member
Scott,

Here is the current version of my SQL code.

Expand|Select|Wrap|Line Numbers
  1. SELECT tblSubformProducts.EventLocation, tblProductInformation.VendorCode, tblProductInformation.[Item#], tblProductInformation.Description, tblProductInformation.Category, tblProductInformation.SubCategory, tblProductInformation.Discontinued, Sum(tblSubformProducts.[# Recieved]) AS [SumOf# Recieved], Sum(tblSubformProducts.[# Sold]) AS [SumOf# Sold], Sum(IIf(tblSubformProducts![#Recieved]>tblSubformProducts![#Sold],tblSubformProducts![#Recieved]-tblSubformProducts![#Sold],"")) AS [In Stock]
  2. FROM tblProductInformation INNER JOIN tblSubformProducts ON (tblProductInformation.[Item#] = tblSubformProducts.[Item #]) AND (tblProductInformation.[Item#] = tblSubformProducts.[Item #]) AND (tblProductInformation.[Item#] = tblSubformProducts.[Item #])
  3. GROUP BY tblSubformProducts.EventLocation, tblProductInformation.VendorCode, tblProductInformation.[Item#], tblProductInformation.Description, tblProductInformation.Category, tblProductInformation.SubCategory, tblProductInformation.Discontinued
  4. HAVING (((tblSubformProducts.EventLocation)=[Forms]![FrmInventoryLocation]![Text37])) OR ((([Forms]![FrmInventoryLocation]![Text37]) Is Null))
  5. ORDER BY tblSubformProducts.EventLocation;
I hope this helps!

I tried to use the code you posted in the last post but it prompted me for #Recieved,#Sold ,Etc. even after I opened it in design view and checked that it was linked to my correct table. If you have any questions or need any other information let me know.
Oct 2 '07 #14
Scott Price
1,384 Recognized Expert Top Contributor
Recheck the spelling carefully, I notice you have it # Recieved, and # Sold once, then the second time is without the space. (By the way... Recieved is spelled ei, as in i before e except after c... Not a real problem, just as long as it's spelled consistently throughout your references :-)

Regards,
Scott
Oct 2 '07 #15
klarae99
85 New Member
Scott,

You were correct in evaluating my space issue (I thought I had removed all the spaces from my field names in the tables but I had not.) Once I put the spaces into the expression the two diologe boxes asking for # Recieved and # Sold stopped popping up but I still got the Error message:

This expression is incorrectly typed, or it is to complex to be evaluated, Etc, etc.

Who thought something so simple could cause so many problems?

Thanks for your continuing efforts.
Oct 4 '07 #16
Scott Price
1,384 Recognized Expert Top Contributor
Try copying and pasting this sql directly into a new query:

Expand|Select|Wrap|Line Numbers
  1. SELECT DISTINCTROW tblProductInformation.[Item#], Sum(tblSubformProducts.[#Recieved]-tblSubFormProducts.[#Sold]) AS [In Stock], tblSubformProducts.EventLocation, tblProductInformation.VendorCode, tblProductInformation.Discontinued, tblProductInformation.Category, tblProductInformation.Subcategory, tblProductInformation.Description
  2. FROM tblProductInformation INNER JOIN tblSubformProducts ON tblProductInformation.[Item#] = tblSubformProducts.[Item#]
  3. GROUP BY tblProductInformation.[Item#], tblSubformProducts.EventLocation, tblProductInformation.VendorCode, tblProductInformation.Discontinued, tblProductInformation.Category, tblProductInformation.Subcategory, tblProductInformation.Description
  4. HAVING (((Sum([tblSubformProducts].[#Recieved]-[tblSubFormProducts].[#Sold]))<>0)) AND (((tblSubformProducts.EventLocation)=[Forms]![FrmInventoryLocation]![Text37]));
  5.  
I set up the two tables in my test database, wrote this query up, and it gives no errors.

I did notice in looking more closely at your last posted sql that you have several duplications, as well as an unnecessary where criteria. Give this one a try and see if it's what you're after.

Regards,
Scott

For the copy and paste, you'll have to paste it into Notepad first to strip out the line numbers.
Oct 4 '07 #17
klarae99
85 New Member
Scott,

I copied the new code into a new queary and did not get any error messages (yeah!), however the number in stock is not seperated by the Items, all the items list the same amount in stock (and I think it is the total # of items per each location) but I need to have the stock per item per location. I hope that makes sense to you. Your additional help is appreciated!
Oct 4 '07 #18
Scott Price
1,384 Recognized Expert Top Contributor
Hi Klara,

I'm sorry, but I can't seem to reproduce that problem in my test db :-( When I populate with test data, using the sql I posted, it does what I think you want done!

I.e. I put three items into the tblProductInfor mation, all with the same vendorID, with varying category, subcategory and descriptions.

Then in the tblSubFormProdu cts I posted a bunch of numbers for these items (at least two of each #Recieved and #Sold). Running the query results in two (I made sure the third of my test items would sum to 0, to 'test' the criteria) items being summed and grouped together accurately.

I'm at a loss right now to know what to tell you!

Regards,
Scott
Oct 4 '07 #19
klarae99
85 New Member
Scott,

Thanks for all your help with this, its good to know that its not just me that runs into a wall.

I also wanted to let you know that I have used scripts to solve many of my other issues with access by reading other posts that are similar to what I need done. Many of those posts were responded to by you and your advice there helped me progress to this point.

Thanks again for all your help, I'll update this post if I do figure out what was going on, or if I determine another way to achive my goal. I'm sure that I'll come up with more questions and I'll see you back here!
Oct 5 '07 #20

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

Similar topics

6
2429
by: paii | last post by:
I have a table that stores job milestone dates. The 2 milestones I am interested in are "Ship Date" TypeID 1 and "Revised Ship Date" TypeID 18. All jobs have TypeID 1 only some jobs have TypeID 18. I need a query that will return the c date for TypeID 18 if it exist else the date for TypeID 1, for all jobs. the table structure is the following Job TypeID
3
4987
by: Steve | last post by:
Form FrmRestock's recordsource is QryFrmRestock. The TransactionDate field's criteria is set ats: Forms!FrmRestock!LastXDays. LastXDays on the form is a combobox where the selections are 30, 60 and 90. The default is set at 30. Question1: When the form opens, there are no records displayed although there are many records that fit the criteria of 30. If I put a button on the form to do a requery and press the button, all the records...
3
579
by: John young | last post by:
I have been looking for an answer to a problem and have found this group and hope you can assist . I have been re doing a data base I have made for a car club I am with and have been trying to make a query that selects from a table as desribed below .. I have a table (Volunteer) that has a member field (memnumber) and a number of fields that are headed in various categories and are yes/no formated
8
4118
by: Tony Williams | last post by:
I have a database that hold s figures for each quarter. I want to create a query whereby the user can ask for the running total of the data upto the quarter they enter into a prompt. The database stores the quarter name in txtmonthlabel (a date field) and the quarters totals in txtdomic (a number field) EG If the user enters March 2004 they get figures upto March 2004, if they enter June 2004 they get total upto June 2004, in other words...
5
11447
by: SuffrinMick | last post by:
Hello - I'm a newbie to coding! I'm working on an access 2000 database which has three tables: tblContacts - A list of customer contacts. tblOrgTypes - A list of organisational types. tblPositions - A list of job descriptions (Contacts can hold more than one position) I want to use a multi-select list box (Containing alphabetical list of positions) to run a query. HELP!
14
2466
by: Crimsonwingz | last post by:
Need to calculate a sum based on a number of factors over a period of years. I can use formula ^x for some of it, but need totals to carry over in the sum and have only been able to do this thus far with a loop in a form. Basically, I have key sums Current savings Current Salary Current deposit amount
1
1804
by: Ivan Carey | last post by:
How can a query display multiple fields with diferent condition on the same field example I have a field name of reason and a field name of duration. I would like to display 2 fileds of total duration but each have different reasion criteria. display Total Recall based on a calculation that adds the total duration for each record that has a criteria of RC on the same query display Total Shift based upon a calculation that adds the
3
6509
by: martlaco1 | last post by:
Trying to fix a query that (I thought) had worked once upon a time, and I keep getting a Data Type Mismatch error whenever I enter any criteria for an expression using a Mid function. Without the criteria, the Mid function returns the values when I run the query. So if one of the values is a "t" (no quotes), can I not ask to isolate that record by putting "t" as a criteria? Nope - error, error. If I put it within the expression itself...
22
31211
by: Stan | last post by:
I am working with Access 2003 on a computer running XP. I am new at using Access. I have a Db with a date field stored as mm/dd/yyyy. I need a Query that will prompt for the month, ie. 6 for June, and will return all records in that month.
0
9564
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9387
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
1
9938
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8822
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7368
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6643
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 then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5270
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
3917
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 we have to send another system
3
2794
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.