473,487 Members | 2,474 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Like inside Iif as Query Criteria

All -

I have a query in which I want to look at a form, and match against 1
value if a specific value has been selected from a list box, or another
value if it has not. I'll have similar criteria in several columns,
checking to see if a specific column should be searched.

In english, my logic goes like this:

If(ListBoxSelection="Name", then Use ListBoxSelection As Criteria, else
Use Other Criteria)

I have this working for exact text matches:
IIf([Forms]![Main]![llb_SearchMe]="Name",([Forms]![main]![tb_Search]),([Forms]![main]![lb_Data_Model]))

But of course, I want to do the search for "near matches," using "Like"
to do the job. Elsewhere, I have no problem using Like, which I have
constructed so:

Like "*" & ([Forms]![main]![tb_Search]) & "*"

But no matter how I add "Like" to my Iif statement, I get no results.
I get no error, but I get no results.

I've tried...and tried...and tried...and tried...

IIf([Forms]![Main]![llb_SearchMe]="Name",(Like "*" &
([Forms]![main]![tb_Search]) & "*"),([Forms]![main]![lb_Data_Model]))

IIf([Forms]![Main]![llb_SearchMe]="Name",(Like "*" &
[Forms]![main]![tb_Search] & "*"),([Forms]![main]![lb_Data_Model]))

IIf([Forms]![Main]![llb_SearchMe]="Name",Like "*" &
([Forms]![main]![tb_Search]) & "*",([Forms]![main]![lb_Data_Model]))

IIf([Forms]![Main]![llb_SearchMe]="Name",Like "*" &
[Forms]![main]![tb_Search] & "*",([Forms]![main]![lb_Data_Model]))

IIf([Forms]![Main]![llb_SearchMe]="Name",Like "*" &
"[Forms]![main]![tb_Search]" & "*",([Forms]![main]![lb_Data_Model]))

Any Ideas?

Patrick

Nov 13 '05 #1
3 13599
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Where are you putting this IIf() function, in the WHERE clause of the
query? If so you need to format it like this:

WHERE IIf([Forms]![Main]![llb_SearchMe] = "Name",
column_name Like "*" & [Forms]![main]![tb_Search] & "*",
column_name = [Forms]![main]![lb_Data_Model])

Substitute your column name for "column_name."
--
MGFoster:::mgf00 <at> earthlink <decimal-point> net
Oakland, CA (USA)

-----BEGIN PGP SIGNATURE-----
Version: PGP for Personal Privacy 5.0
Charset: noconv

iQA/AwUBQmaBYYechKqOuFEgEQJl3gCdEG6YAXukYZWtlUdoSU5So6 f7vy0AoMWD
0RikTd0OSusjiYm6+kw0z5Yq
=KRXE
-----END PGP SIGNATURE-----

Patrick A wrote:
< SNIP >
I have this working for exact text matches:
IIf([Forms]![Main]![llb_SearchMe]="Name",([Forms]![main]![tb_Search]),([Forms]![main]![lb_Data_Model]))

But of course, I want to do the search for "near matches," using "Like"
to do the job. Elsewhere, I have no problem using Like, which I have
constructed so:

Like "*" & ([Forms]![main]![tb_Search]) & "*"
< SNIP >
IIf([Forms]![Main]![llb_SearchMe]="Name",(Like "*" &
([Forms]![main]![tb_Search]) & "*"),([Forms]![main]![lb_Data_Model]))


< SNIP >
Nov 13 '05 #2
I'm trying to type it in the Criteria Row of the Design View of the
Query.

I'm typing in:

IIf([Forms]![Main]![llb_SearchMe]="Name",Like "*" &
[Forms]![main]![tb_Search] & "*",[Forms]![main]![lb_Data_Model])

The resulting SQL looks like this:

WHERE
(((METADATA_REPORT_DATA_FIELD.COLUMN_NAME)=IIf([Forms]![Main]![llb_SearchMe]="Name",(METADATA_REPORT_DATA_FIELD.COLUMN_NAME )
Like "*" & [Forms]![main]![tb_Search] &
"*",[Forms]![main]![lb_Data_Model])));

But I get no results.

Nov 13 '05 #3
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

You didn't format the WHERE clause as I suggested. Here it is w/ your
column name (do this in the SQL View - it's easier than the QBE design
grid):

WHERE
IIf([Forms]![Main]![llb_SearchMe]="Name",
METADATA_REPORT_DATA_FIELD.COLUMN_NAME
Like "*" & [Forms]![main]![tb_Search] & "*",
METADATA_REPORT_DATA_FIELD.COLUMN_NAME=[Forms]![main]![lb_Data_Model])

Is there really a column named "COLUMN_NAME" in your table
"METADATA_REPORT_DATA_FIELD"? Not a very descriptive name. I could say
the same about your table name. It appears as if you've got some major
craziness going on there. :-O
--
MGFoster:::mgf00 <at> earthlink <decimal-point> net
Oakland, CA (USA)

-----BEGIN PGP SIGNATURE-----
Version: PGP for Personal Privacy 5.0
Charset: noconv

iQA/AwUBQmaVHYechKqOuFEgEQLfEwCfeu6rUPdWDRO2UDZVX4DyC2 +6SyUAn0Zq
tH5d1w2GebNAFZDy7yZDrKBN
=D1IE
-----END PGP SIGNATURE-----

Patrick A wrote:
I'm trying to type it in the Criteria Row of the Design View of the
Query.

I'm typing in:

IIf([Forms]![Main]![llb_SearchMe]="Name",Like "*" &
[Forms]![main]![tb_Search] & "*",[Forms]![main]![lb_Data_Model])

The resulting SQL looks like this:

WHERE
(((METADATA_REPORT_DATA_FIELD.COLUMN_NAME)=IIf([Forms]![Main]![llb_SearchMe]="Name",(METADATA_REPORT_DATA_FIELD.COLUMN_NAME )
Like "*" & [Forms]![main]![tb_Search] &
"*",[Forms]![main]![lb_Data_Model])));

But I get no results.

Nov 13 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
4966
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...
2
2580
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...
0
3482
by: starace | last post by:
I have designed a form that has 5 different list boxes where the selections within each are used as criteria in building a dynamic query. Some boxes are set for multiple selections but these list...
4
5345
by: carl.barrett | last post by:
Hi, I have a list box that displays 2 columns. Behind it sits a query with five columns. These are Column1 (DOB), column2 (a concatenated string of Surname Forname, Title), Column3 (Surname),...
1
3365
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...
1
1626
by: Jer | last post by:
I have a query that uses LIKE in the criteria. The criteria I am using is: LIKE "Program*". When I look at the query results it works fine. When I try to open the query as a recordset using Dim...
2
12205
by: ChasW | last post by:
Greetings, I have a form that uses a query as its record source. In the form I have a text box that uses this as its control source: =DCount("", "qry_Search_by_Name") The DCount function...
11
6366
by: Bruce Lawrence | last post by:
Ok, I'm baffled... I'm making a query in access 97 between 2 tables. There is a field in both tables called "DWGNO". OPENORD has a record with a DWGNO of "00000012345" DIEDATA has a record...
9
2428
by: Drum2001 | last post by:
Hello All! I am using the following code during an On Click event for a button. It works properly to create a query for a report: Private Sub Command14_Click() If IsNull(Me.Text30) Then ' No...
0
7106
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,...
0
6967
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...
0
7181
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...
0
5442
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
4874
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
4565
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
3076
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...
0
1381
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
600
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.