Can You Query Using Multiple Criteria From Same Field?
Mar 9, 2007
Hi all,
I posted something similar to this before
http://www.access-programmers.co.uk/forums/showthread.php?t=124289
But i didnt get it figured out.
Is it possible to use the same field for multiple criteria in a query?
the one i would like to base it on is taskID.
i just want the total time to be called admin time if taskid=2 and investigative time if taskid<>2.
Ive tried it with single and multiple queries in one and am recieving errors with both. help is always appreciated!
Was wondering if there is a way without building individual update queries, to update info in one field that has multiple criteria ?
Basically I need to change/update daily multiple ID numbers to new ID numbers, long story on why this needs to be done but for now I need to do it this way.
Example: 12345 update to ABCDE, 6789 update to FGHI, etc. These ID's are all within the same field in the table.
It works fine running each ID one at a time but was wondering if it is possible to do all these updates within one query or code ?
I need to update the periodtype field in my table depending on different values in the field Formtype- I am looking to do this without having to use VBA. I have the following fields in a table - I want to update the value of the field Period_type as follows -
When Formtype is 10-Q, update Periodtype to "Quarterly"
When Formtype is 10-K, update Periodtype to "Annual"
The current value of Periodtype for both formtypes is "Semiannual"
Hello, ...I'm not sure if I'm making this question more complex or not or if it's even possible? (I would think so) Anyway...What I am trying to do is create a form in which I can input more than one criteria into a field - We will cal it txtSetValues. Then via a button open a query that will use txtCode as the criteria for searching records in a table. The table is called: tblMASTERTABLE-EmpCount query is called: qryEmpCount
The table currently only has two field; ORG and Name. The criteria I have in ORG is: Like [Forms]![frmEmpCount]![txtCode] I currently can find any specific ORG just fine. I can also use the wildcard and that works fine. But how can I set it up so that I can enter in multiples... For example, I would like to find all employees that there org is either; AL001 OR AL010 OR AL100 - The wildcard will 'Almost' do it in some circumstances, but it may gather some orgs that I don't want in this list. I hope I am explaining this in an easily understood fashion?
Thanks, ---roystreet P.S. Now I know I could just make multiple fields in the form (ie; txtCode2, txtCode3,etc) and then just add those as criteria in the query, but I was hoping that I wouldn't have to do that.
This is the trimmed down part of the query that is causing the result.
Code: SELECT [tblP&E].PnE_ID, tblUsage.Measurement AS UOM, IIf([tblUsage]![Week_Ending]=#6/20/2014#,[tblUsage]![Usage],"") AS [June 20], IIf([tblUsage]![Week_Ending]=#6/27/2014#,[tblUsage]![Usage],"") AS [June 27], IIf([tblUsage]![Week_Ending]=#7/4/2014#,[tblUsage]![Usage],"") AS [July 4], IIf([tblUsage]![Week_Ending]=#7/11/2014#,[tblUsage]![Usage],"") AS [July 11] FROM tblUsage RIGHT JOIN ([tblP&E] LEFT JOIN tblCosts ON [tblP&E].[PnE_ID] = tblCosts.[PnE_ID]) ON tblUsage.PNE_ID = [tblP&E].PnE_ID;
I have a query that displays all records. I need it to limit based on multiple criteria in a single field. I.E... instead of all employees from every section, I just want it to display employees from section A, C, D, F one time and next time maybe go with section B, C, D. For some reason the solution eludes my little brain.
I have two tables, Students and AttendanceRecords.
Students just has studentID and studentName
AttendanceRecords has AttRecID, studentID, presence, thedate
I'm looking to create what looks like an Excel grid, with the last 10 days as columns and the student names as rows. All the cells in middle will be filled with the values of 'presence' for that student/day (e.g., P for present, A for absent).
Here's something I'm currently considering.
-I could make 10 queries, each using LEFT JOIN to connect studentName with presence & thedate on studentID, varying the 10 queries only in that 'thedate' will have a criteria of Date() -1 , Date() -2 , etc. -If I'm understanding it correctly, I'll then have 10 tables, each containing 3 rows -- student name, presence, and the date (with each table having only 1 date repeated throughout). -I could then join those 10 queries together on studentName, theoretically resulting in 1 big table with all the student names and the corresponding presence values for the last 10 days
If I do that, I could make a form in Continuous view and have each row show the studentName and 10 text boxes closely bunched up with presence values.
That seems very inefficient? Making 10 queries separately and then manually merging them seems redundant.
Also, now that I think about it, will the final product end up being read-only, or if the user changes one of the presence cells will it update the corresponding record in AttendanceRecord?
I am trying to make a query that outputs the minimum "Need Year" AND ALSO if the need year was equal to 9999 it shows "NO DATA".
This is what I have so far for checking the minimum value:
field: Need Year: MinofList(PMS_output!pqi_ny,PMS_output!iri_ny,PMS_ output!sdi_ny,pms_output!sai_ny)
I am not sure if I should be putting it in the criteria to check whether this minimum value (need year) equals to 9999 or not and if it does, it says "NO DATA" instead of 9999.
I would like to display a report based on the table called "expenses", filtered by:
- "from" (datefrom field) and "to" (dateto field) date on "payment date" field; - multiple criteria on same field called "payment method" (I would like to include only payment methods "check" and "credit card", but not the other payment methods in the field, such as "cash", "transfer", etc.)
For that end I made a query based on the table "expenses", and in the "payment date", in the criteria field, I entered:
between [form]![formname]![datefrom] and [form]![formname]![dateto]
This works fine so far, however when I attempt to add multiple criteria on the "payment method" field, it does not filter accurately any longer. In the same row of the criteria field where I completed the date criteria, I enter "check". In the next row, same field, I enter "credit card".
Since it doesn't work, I tried putting both arguments in the same line as the date criteria (always in the payment method field) as: "check" and "credit card" but still does not work (now it filters the payment method correctly, but the dates filter appear as if I have never completed them).
I'm working with a table of bird survival data I am trying to summarize in a query. I've got a bit of a roundabout way to achieve my goal, but I'm curious if there is a simpler approach.
Background : In my table, each row represents a day I check a given nest and includes a [Nest ID] (not unique, multiple visits to each nest), a [visit ID] (auto numbered, so it's a unique value for each visit at each nest), the calendar day I visited a nest [Date], and [Survive] (1 or 0) depending on whether a nest survived or failed.
I'm trying to convert this detailed table into one that is more concise. Instead of each visit to a nest being a row, each nest becomes a row with 4 fields: The Nest ID, the minimum date (the day I found a nest), the last day a nest was checked (Max[Date]), and the last day a nest was checked alive (essentially max date where survival=1).
My current solution is to run 3 separate queries. The first queries the max date where survival=1, the second queries the max and min dates regardless of any other criteria, and the third brings both queries together.
I am curious if there is a way to create the same final product in a single query rather than doing multiple ones as I have done?
I'm working on a purchasing app in access. At this point i'm working on the reporting module. I want a user to be able to fill out a start date (text box), end date (text box), and select a code from a list, hit Run Query, and have it pull up a report listing the date that the selected code was used, between the start and end date, and display other info as well.
The problem i'm having is that i can get the date ranges to work, or the code to work, but not both of them. Here's what i have in my query:
I have 3 fields that I need to run a query on. Date_Image, IMAGE_SYSTEM and DATE_TO_BR. If there is no entry in either fields, it should be part of the query. If entry is in both Date_Image and Image_system, I do not need those results in the query. If Date_to_br field is empty, I must have an entry in the other 2 fields before this record is not displayed in the query. I hope I was able to explain this clear enough. I was trying to do this with the IS null and Is Not Null expressions, but I am not getting the results I want.
This is probably an easy one but for some reason I'm not finding it in any of my reference sources.
I'm trying to set up a query that calculates tax my company owes the gov't, and the tax varies based on year to date totals. The 1st $30,000 is taxed at 4% and everything over $30,000 is taxed at 5%.
tblOrders has fields for date, CustomerID, OrderID and OrderTotal. Can the query have an expression field ("UpTo30") for ([OrderTotal] <=$30000) and also a 2nd expression ("Over30") for ([OrderTotal]>$30000)? And in the same query is it possible to also include the calculated fields for ([Upto30]*0.04) and ([Over30]*0.05)?
My main question is where to put the criteria - all I'm seeing talks about multiple criteria being State=NH AND/OR Name=R*, not multiple criteria on the same field. When I try WHERE statements I just get error msg no matter what the syntax is.
Hi all I have a query linked to a report that prints a worksheet specific to a individual work item. This report/query picks up the Work_ID value on a form. I have 2 other forms displaying the same work with different amounts of detail. Rather than create a new report/query to run from each form, I am trying to use the one query/report from each form. The problem is that I cannot get Access to recognise the Work_ID value from the other forms. I have tried the following:
In the Work_ID criteria field building an SQL statement as below [Forms]![frmVCRUpdate]![Work_ID] Or [Forms]![frmVCRShort]![Work_ID] Or [Forms]![frmVCRLong]![Work_ID] - This does not work, it keeps asking for the frmVCRUpdate Work_ID value when I try to run the query from the other forms Adding 2 extra Work_ID Values to the query and on the 2nd and 3rd criteria lines specifying that it look for the Work_ID value from the other forms but I get the error above.
Any suggestions on how I can make this work would be appreciated, I'm not sure what else to do. Craig
I'm trying to build a select query where it prompts the user for a few parameters. I've been having issues where people would misspell the vendor name and nothing pops up. I changed the vendor to Like [Vendor Name] & "*" but now I can't use the parameter of PO# without everything popping up. I have attached the SQL view. Thank you for any suggestions.
SELECT [Main Payment].[Batch#], [Main Payment].VendorName, [Main Payment].VoucherPrefix, [FY08 PAYMENT detail].VoucherNumber, [Main Payment].VoucherSuffix, [FY08 PAYMENT detail].Vchline1, [FY08 PAYMENT detail].PONo, [FY08 PAYMENT detail].InvoiceDate, [FY08 PAYMENT detail].InvoiceID, [FY08 PAYMENT detail].Amount FROM [Main Payment] INNER JOIN [FY08 PAYMENT detail] ON [Main Payment].VoucherNumber = [FY08 PAYMENT detail].VoucherNumber WHERE ((([FY08 PAYMENT detail].PONo)=[Enter PO#])) OR ((([Main Payment].[Batch#])=[Enter Batch #])) OR ((([FY08 PAYMENT detail].VoucherNumber)=[Enter Voucher #])) OR ((([Main Payment].VendorName) Like [Enter Vendor Name] & "*"));
I want to create a query with multiple conditions. Basically if the person Passes any of this trainings they need to show up in my query..how do you do it?
SELECT tblMasterUsers.userid, tblMasterUsers.Licenses, tblMasterUsers.firstname, tblMasterUsers.lastname, tblMasterUsers.email, tblMasterUsers.npn, tblMasterUsers.Region, tblMasterUsers.ABSID, CMPreport2014.[Ahip status], CMPreport2014.[LP Status] AS [AZ Product Training], CMPreport2014.[LP Status1] AS [CA Product Training], CMPreport2014.[LP Status2] AS [OR WA Product Training], CMPreport2014.[LP Status3] AS [Fraud Waster Abuse],
My query is coming along nicely, but as always once one problem is solved you find another :rolleyes: !
My problem is that I have thus far specified criteria for the field OrdDeliveryCountry, but this field is not filled in unless the delivery address is different from the default address for the customer, therefore it is frequently blank and so the query wasn't finding all records, only those where the Delivery Address was specific to the order.
I want to use the IIf function to make an expression to say (in linguistic terms): If OrdDeliveryCountry is blank, then use the country in the Customers table.
Sounds simple enough, but the criteria currently is: WHERE (((ORDERS.ORDDELIVERYCOUNTRY) = "Austria" OR (ORDERS.ORDDELIVERYCOUNTRY) = "Belgium" OR (ORDERS.ORDDELIVERYCOUNTRY) = "Cyprus" OR (ORDERS.ORDDELIVERYCOUNTRY) = "Czech Republic" OR (ORDERS.ORDDELIVERYCOUNTRY) = "Denmark" OR (ORDERS.ORDDELIVERYCOUNTRY) = "Estonia" OR (ORDERS.ORDDELIVERYCOUNTRY) = "Finland" OR (ORDERS.ORDDELIVERYCOUNTRY) = "France" OR (ORDERS.ORDDELIVERYCOUNTRY) = "Germany" OR (ORDERS.ORDDELIVERYCOUNTRY) = "Greece" OR (ORDERS.ORDDELIVERYCOUNTRY) = "Hungary" OR (ORDERS.ORDDELIVERYCOUNTRY) = "Ireland" OR (ORDERS.ORDDELIVERYCOUNTRY) = "Italy" OR (ORDERS.ORDDELIVERYCOUNTRY) = "Latvia" OR (ORDERS.ORDDELIVERYCOUNTRY) = "Lithuania" OR (ORDERS.ORDDELIVERYCOUNTRY) = "Luxembourg" OR (ORDERS.ORDDELIVERYCOUNTRY) = "Malta" OR (ORDERS.ORDDELIVERYCOUNTRY) = "Holland" OR (ORDERS.ORDDELIVERYCOUNTRY) = "Poland" OR (ORDERS.ORDDELIVERYCOUNTRY) = "Portugal" OR (ORDERS.ORDDELIVERYCOUNTRY) = "Slovakia" OR (ORDERS.ORDDELIVERYCOUNTRY) = "Slovenia" OR (ORDERS.ORDDELIVERYCOUNTRY) = "Spain" OR (ORDERS.ORDDELIVERYCOUNTRY) = "Sweden") AND ((PRODUCTS.PRODUCTNAME) NOT LIKE "*Upgrade" AND (PRODUCTS.PRODUCTNAME) NOT LIKE "*Repair" AND (PRODUCTS.PRODUCTNAME) NOT LIKE "*Rpr" AND (PRODUCTS.PRODUCTNAME) NOT LIKE "*Commission") AND ((ORDERS.[DEMO/SALEID]) = 2))
So how do I combine the IIf(expr,truepart,falsepart) with "Is Not x Or x Or x"?I.E. I need to get it to exclude records where OrdDeliveryCountry does not equal one in the list, and if that is blank then the Country field in the Customers table does not equal one in the list?
My attempt is this, but I think I'm way off the mark
SELECT ORDERS.SHIPDATE, PRODUCTS.[STANDARD TARRIFF NUMBER], [ORDER DETAILS].[QUANTITY] * [ORDER DETAILS].[UNITPRICE] * (1 - [DISCOUNT]) * (1 - [SPECIAL DISCOUNT]) AS LINETOTAL, [ORDER DETAILS].QUANTITY, ORDERS.ORDDELIVERYCOUNTRY, ORDERS.ORDERID, [ORDER DETAILS].PRODUCTID FROM CUSTOMERS RIGHT JOIN (PRODUCTS RIGHT JOIN (ORDERS LEFT JOIN [ORDER DETAILS] ON ORDERS.ORDERID = [ORDER DETAILS].ORDERID) ON PRODUCTS.PRODUCTID = [ORDER DETAILS].PRODUCTID) ON CUSTOMERS.CUSTOMERID = ORDERS.CUSTOMERID WHERE (((ORDERS.ORDDELIVERYCOUNTRY) = IIF(ISNULL([ORDERS]![ORDDELIVERYCOUNTRY]),([CUSTOMERS]![COUNTRY] NOT LIKE "Austria" OR (ORDERS.ORDDELIVERYCOUNTRY) = "Belgium" OR (ORDERS.ORDDELIVERYCOUNTRY) = "Cyprus" OR (ORDERS.ORDDELIVERYCOUNTRY) = "Czech Republic" OR (ORDERS.ORDDELIVERYCOUNTRY) = "Denmark" OR (ORDERS.ORDDELIVERYCOUNTRY) = "Estonia" OR (ORDERS.ORDDELIVERYCOUNTRY) = "Finland" OR (ORDERS.ORDDELIVERYCOUNTRY) = "France" OR (ORDERS.ORDDELIVERYCOUNTRY) = "Germany" OR (ORDERS.ORDDELIVERYCOUNTRY) = "Greece" OR (ORDERS.ORDDELIVERYCOUNTRY) = "Hungary" OR (ORDERS.ORDDELIVERYCOUNTRY) = "Ireland" OR (ORDERS.ORDDELIVERYCOUNTRY) = "Italy" OR (ORDERS.ORDDELIVERYCOUNTRY) = "Latvia" OR (ORDERS.ORDDELIVERYCOUNTRY) = "Lithuania" OR (ORDERS.ORDDELIVERYCOUNTRY) = "Luxembourg" OR (ORDERS.ORDDELIVERYCOUNTRY) = "Malta" OR (ORDERS.ORDDELIVERYCOUNTRY) = "Holland" OR (ORDERS.ORDDELIVERYCOUNTRY) = "Poland" OR (ORDERS.ORDDELIVERYCOUNTRY) = "Portugal" OR (ORDERS.ORDDELIVERYCOUNTRY) = "Slovakia" OR (ORDERS.ORDDELIVERYCOUNTRY) = "Slovenia" OR (ORDERS.ORDDELIVERYCOUNTRY) = "Spain" OR (ORDERS.ORDDELIVERYCOUNTRY) = "Sweden"), (([ORDERS]![ORDDELIVERYCOUNTRY]) NOT LIKE "Austria" OR (ORDERS.ORDDELIVERYCOUNTRY) = "Belgium" OR (ORDERS.ORDDELIVERYCOUNTRY) = "Cyprus" OR (ORDERS.ORDDELIVERYCOUNTRY) = "Czech Republic" OR (ORDERS.ORDDELIVERYCOUNTRY) = "Denmark" OR (ORDERS.ORDDELIVERYCOUNTRY) = "Estonia" OR (ORDERS.ORDDELIVERYCOUNTRY) = "Finland" OR (ORDERS.ORDDELIVERYCOUNTRY) = "France" OR (ORDERS.ORDDELIVERYCOUNTRY) = "Germany" OR (ORDERS.ORDDELIVERYCOUNTRY) = "Greece" OR (ORDERS.ORDDELIVERYCOUNTRY) = "Hungary" OR (ORDERS.ORDDELIVERYCOUNTRY) = "Ireland" OR (ORDERS.ORDDELIVERYCOUNTRY) = "Italy" OR (ORDERS.ORDDELIVERYCOUNTRY) = "Latvia" OR (ORDERS.ORDDELIVERYCOUNTRY) = "Lithuania" OR (ORDERS.ORDDELIVERYCOUNTRY) = "Luxembourg" OR (ORDERS.ORDDELIVERYCOUNTRY) = "Malta" OR (ORDERS.ORDDELIVERYCOUNTRY) = "Holland" OR (ORDERS.ORDDELIVERYCOUNTRY) = "Poland" OR (ORDERS.ORDDELIVERYCOUNTRY) = "Portugal" OR (ORDERS.ORDDELIVERYCOUNTRY) = "Slovakia" OR (ORDERS.ORDDELIVERYCOUNTRY) = "Slovenia" OR (ORDERS.ORDDELIVERYCOUNTRY) = "Spain" OR (ORDERS.ORDDELIVERYCOUNTRY) = "Sweden"))) AND ((PRODUCTS.PRODUCTNAME) NOT LIKE "*Upgrade" AND (PRODUCTS.PRODUCTNAME) NOT LIKE "*Repair" AND (PRODUCTS.PRODUCTNAME) NOT LIKE "*Rpr" AND (PRODUCTS.PRODUCTNAME) NOT LIKE "*Commission") AND ((ORDERS.[DEMO/SALEID]) = 2)) ORDER BY ORDERS.SHIPDATE DESC;
My thoughts:
Maybe I need to re-structure the WHERE clause? Would it work if the IIf expresssion was in the SELECT part not the WHERE part?
I would really appreciate some help with this: I'm not sufficiently familiar with structuring statements as complex as this and I don't know all the syntax rules etc.
Embarrassingly, I'm not even to the point where I can ask a specific question about the query(ies) I think I need.
Here's where I'm starting from and where I want to go... maybe it will make enough sense for somebody to point me in the right direction.
I have sales data that contains line items for every item sold over the past X number of years. For each line, there are six key attributes that I'm concerned with.
For simplicity here's a scaled down example of the data for each line.
For each attribute, there are at least five possibilities.
I have been asked to find monthly sales trends on about 20 unique combinations of these various attributes. An example might be, the monthly sales totals for:
I've set up a query that can give me the information I'm looking for one month at a time, but I want to believe there is a way to have Access do some of the grunt work, rather than me having to change the variables one by one and copy/paste each result into my new file.
Is there some reading or previous posts I could review that might get me thinking about this in the right way?
I am currently having problems with a multiple criteria query with combo boxes (see attached file).
The problem:
- When user defines all 3 criteria (e.g. selects Project: A, Category: Services and Equipment Type: Packages), the query returns a result - no problem here.
- When user defines no fields (i.e. all combo boxes empty), query returns all records - again, not a probelm.
- However, say a user wants to display all records belonging to just Project: A, for example, the query returns no records. Obviously, there a a number of combinations of this (another example would be a user wanting to show records from project: B, with Category: Equipment Type).
I have included the Is Null statement in the query but to no avail. Could anyone advise on a solution based on the attached database. Your help would be greatly appreciated!
I was searching through here looking for a solution to the following problem: I am building a Capacity database for work. The requirements require that users be able to sort by numerous criteria (Forecast Date, Portfolio, Market, Bucket, Month), all from a simple form that will spit out the results. Rather than creating unique queries for each combination of criteria(way too many!) or creating the SQL text in VBA, I played around until I came up with the following(which may have been done already, but I can't find it on here, so I'm not claiming to be brilliant...LOL). I have dropdowns on my form for each sort criteria-(Forecast Date, Portfolio, Market, Bucket, Month)
Then I created a query and for each criteria, I put this in: Like (IIf(IsNull([Forms]![frmWAOFAdjustments]![Bucket]),"*",[Forms]![frmWAOFAdjustments]![Bucket]))
So if the user leaves a dropdown blank, the query simply brings back all the results from that field (Like *).
The text in bold is simply replaced with the dropdown name for each segmentation criteria. Next to each dropdown is a button that clears the dropdown box and requeries the listbox with the results(in case the user doesn't want to remove a criteria. This makes running searches for a specific number of accounts easy for the user and easy on me..lol.
Hopefully this can help someone out with a similar problem. I have learned so much from this forum, I just wanted to give something back. If anyone has any questions on this, just let me know.
Alright I've been picking my brain for the past hour trying to figure this one out...
I have 3 tables... 1) Retailers-RetailerID, RetailerName, address etc. (500 entries) 2) Distributors- DistributorID, DistName (10 entries) 3) Uses- RetailerID, DistributorID
Sample data is as follows for 'Uses' table: RetailerID DistributorID 1 1 1 3 2 1 2 6 3 4 3 5 4 8
I am trying to create a search form based on a query which will return retailer information for those retailer who use multiple distributors.
For Example...There will be 2 text boxes and a user can enter a distributorID in these text boxes. If only 1 distributorID is entered, it will display records for that one.
I have tried the following but I have been unsuccessful:
SELECT Uses.RetailerID, Retailers.Address, Count(Uses.RetailerID) AS CountOfDistributorID FROM Retailers INNER JOIN (Distributor INNER JOIN Uses ON Distributor.DistributorID = Uses.DistributorID) ON Retailers.RetailerID = Uses.RetailerID WHERE Uses.DistributorID = 1 GROUP BY Uses.RetailerID, Retailers.Address HAVING Count(Uses.RetailerID) > 1
Is this possible to accomplish with the way I designed this database? If so, can I get a little advice? I know this is a long question that can't be answered in full but I would just need to basics in order to be on my way. Thanks in advance!
I have a table(Product Change) with these fields: Tracking Number Approved (a check box) Engineering (text box that represents department) Purchasing (text box that represents department) Quality (text box that represents department) Production (text box that represents department) Customer Service (text box that represents department)
I want my query results to show all records that have the "Approved" check box...checked, and then only the records that have one of the Department fields with a null value. So I'm looking to see only records that are "Approved" and out of those....only the records with at least one department field empty(Null).
Any help doing this is SQL view would be great...or even design view.