473,698 Members | 2,225 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Using IIF and LIKE in Query Criteria

2 New Member
This is my first post to the forum and hoping I can get help as I have spent a way too much time on this problem, and thinking it is probably something really simple to resolve.

I am using Access 2000 and trying to create a Query which draws its parameters from a Report Criteria Selection Form, which will define the data source for a report.

On a Report Selection Form if user enters a part# containing "PP"
then criteria will be for the exact part entered.
If part# entered does not contain "PP", then I want the results to do a Like Statement for all parts containing the text entered.

When I manually type a like statement e.g. Like "AB123*" in criteria of query design grid everything works fine, and I get AB123, AB123PP01, AB123PP07. But... when I try and pull the parameter from report selection form and add an IIF statement, I get no results.

Is Access 2000 not capable of using "Like" in an IIF statement? Is there any other way for me to accomplish this?

My Select statement looks like this:

Expand|Select|Wrap|Line Numbers
  1. SELECT Measurement.ProdId, Measurement.Subgrp_Num, Measurement.MeasDate, Measurement.MeasTime, Str([MeasDate])+" "+Str([MeasTime]) AS [DateTime], Measurement.CharName, Measurement.Subgrp_Order, Measurement.UserCont1, Measurement.UserCont2, Measurement.UserCont3, Measurement.Comment, Measurement.Measurement, Product.UserTitle1, Product.UserTitle2, Product.UserTitle3, Measurement.CorAction
  2. FROM Measurement INNER JOIN Product ON Measurement.ProdId = Product.ProdId
  3. WHERE (((Measurement.ProdId)=IIf(InStr(6,[Forms]![ReportSelection]![Part],"PP")>0,[Forms]![ReportSelection]![Part],([Measurement].[ProdId]) Like "[Forms]![ReportSelection]![Part]" & "*")) AND ((Measurement.MeasDate) Between [Forms]![ReportSelection]![BeginDate] And [Forms]![ReportSelection]![EndDate]))
  4. ORDER BY Measurement.ProdId, Measurement.Subgrp_Num DESC , Measurement.CharName, Measurement.MeasDate, Measurement.MeasTime;
- unfortunately upgrading Access is not an option :(

If anyone could help, it would be much appreciated.

Thanks,
Mary
Mar 17 '07 #1
3 4213
MMcCarthy
14,534 Recognized Expert Moderator MVP
Hi Mary

Try this ...

Expand|Select|Wrap|Line Numbers
  1. SELECT Measurement.ProdId, Measurement.Subgrp_Num,
  2. Measurement.MeasDate, Measurement.MeasTime, Str([MeasDate])+"
  3. "+Str([MeasTime]) AS [DateTime], Measurement.CharName,
  4. Measurement.Subgrp_Order, Measurement.UserCont1,
  5. Measurement.UserCont2, Measurement.UserCont3,
  6. Measurement.Comment, Measurement.Measurement,
  7. Product.UserTitle1, Product.UserTitle2, Product.UserTitle3,
  8. Measurement.CorAction
  9. FROM Measurement INNER JOIN Product 
  10. ON Measurement.ProdId = Product.ProdId
  11. WHERE (((Measurement.ProdId)
  12. Like IIf(InStr(6,[Forms]![ReportSelection]![Part],"PP")>0,
  13. [Forms]![ReportSelection]![Part],
  14. [Forms]![ReportSelection]![Part] & "*")) 
  15. AND ((Measurement.MeasDate) 
  16. Between [Forms]![ReportSelection]![BeginDate] 
  17. And [Forms]![ReportSelection]![EndDate]))
  18. ORDER BY Measurement.ProdId, Measurement.Subgrp_Num DESC,
  19. Measurement.CharName, Measurement.MeasDate,
  20. Measurement.MeasTime;
Mary
Mar 17 '07 #2
Clearview
2 New Member
Hi Mary

Try this ...

Expand|Select|Wrap|Line Numbers
  1. SELECT Measurement.ProdId, Measurement.Subgrp_Num,
  2. Measurement.MeasDate, Measurement.MeasTime, Str([MeasDate])+"
  3. "+Str([MeasTime]) AS [DateTime], Measurement.CharName,
  4. Measurement.Subgrp_Order, Measurement.UserCont1,
  5. Measurement.UserCont2, Measurement.UserCont3,
  6. Measurement.Comment, Measurement.Measurement,
  7. Product.UserTitle1, Product.UserTitle2, Product.UserTitle3,
  8. Measurement.CorAction
  9. FROM Measurement INNER JOIN Product 
  10. ON Measurement.ProdId = Product.ProdId
  11. WHERE (((Measurement.ProdId)
  12. Like IIf(InStr(6,[Forms]![ReportSelection]![Part],"PP")>0,
  13. [Forms]![ReportSelection]![Part],
  14. [Forms]![ReportSelection]![Part] & "*")) 
  15. AND ((Measurement.MeasDate) 
  16. Between [Forms]![ReportSelection]![BeginDate] 
  17. And [Forms]![ReportSelection]![EndDate]))
  18. ORDER BY Measurement.ProdId, Measurement.Subgrp_Num DESC,
  19. Measurement.CharName, Measurement.MeasDate,
  20. Measurement.MeasTime;
Mary
It Worked! Thanks so much!
Mar 17 '07 #3
MMcCarthy
14,534 Recognized Expert Moderator MVP
It Worked! Thanks so much!
No problem.

Glad to help.

Mary
Mar 18 '07 #4

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

Similar topics

2
2587
by: Jennifer | last post by:
I have a query with 5 possible criteria via a form. If criteria is not entered, I use the like Nz() function on the backend query to use an "*" for criteria fields left blank. The query is not returning the full recordset. If the Like Nz() function is used on 1 field, it returns the correct number of records. As soon as I add it on more then one field, it loses records somehow. ??? For example, SELECT .GlossaryID,...
4
2434
by: nick_faye | last post by:
hi, hope someone can help me. i am a newbie in creating queries and i want to create a query wherein i only get entries from my table where values of fields 2, 3 and 4 are not zeros. for example: field1 field2 field3 field4 one 1 0 0 two 2 0 3 three 0 0 0 my query should only get entries one and two. can somebody show me
3
2968
by: I_was_here | last post by:
Hey if anyone is a query pro please showoff some knowledge thx. Ie: I have a table with : part price location qty 1 part repeats throughout the table and its price remains the same but it has multiple locations so I'll have entries like:
12
6378
by: Steve Elliott | last post by:
I have a query set up to gather together data between two specified dates. Shown in the query column as: Between #24/09/2004# And #01/10/2004# Is it possible to enter several different date ranges, ie between 24/09/2004 and 01/10/2004 together with 05/10/2004 and 07/10/2004 ? If I enter the "Between" criteria on different lines it returns no data.
1
3385
by: S. van Beek | last post by:
Dear reader, How can I filter a numeric field with Like as criteria in a query. To filter a numeric field with <10 as criteria this will com back with the result of those records for which the value is smaller as teen. But in case this value is variable and you prefer to work with "Like
11
3864
by: DP | last post by:
hi, i have a films table and form. i have a txt field in teh form called txtSearch , and i;ve created a query with all the film table fields in it. how can i get the query to load up, wth the required film infromation in it?? i've a query called qryFilmQuery
7
3785
by: keliie | last post by:
Hello Just a quick question that I've spent a few hours trying to solve with no luck (although one would think this should be fairly easy). I have a form with a subform. The subform is based on a query. The criteria for the query is based on the user's input in the main form. One of the user inputs is a field called "Vendor_Name" (in the form of a combo box). I would like the query to run for all "Vendor_Name" if the user leaves the...
1
4281
by: tomlebold | last post by:
Having problems displaying query results from combo boxes on a sub form, which is on the same form that is used to select criteria. This has always worked form me when displaying query results on another main and sub form. The requery on the sub form and refresh comands on the main form do not work when the form is first displayed and when the selection criteria is changed. Should I be doing a refresh and then repaint of the sub form. ...
13
4984
by: Robertf987 | last post by:
Hi, Yet another thing I need help with I'm affraid. I'll first explain what I want, then I'll try to explain what I have. I'm using Microsoft Access 2000. What I want is to be able to do a search, taking it's criteria fro a text box on a form. This bit is easy, done it a jazillion times. But I want it to be an "Or" search. If I type in it "Cakes, Cheese", I don't want it to bring up results that contain cakes AND cheese, I want it to bring...
0
8603
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,...
0
9157
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
8893
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
7723
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
6518
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
4366
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...
0
4619
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
2328
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2001
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.