Wildcard Search in Text Field

D

djf

The wildcard search is not working for the SHOP field in the following code.
I want to search the SHOP field for all strings that contain an A. I have
this code in an Access query. Everything works correctly except for the *
parameter. What is the proper syntax?

IIf([RECFROM]="JOB" And [PROG]="Seattle" And [SHOP] Like "*A*","Seattle"
 
D

djf

In the Field: line of the access query grid.

Jeff Boyce said:
Where are you running this code?

Regards

Jeff Boyce
Microsoft Office/Access MVP

djf said:
The wildcard search is not working for the SHOP field in the following
code.
I want to search the SHOP field for all strings that contain an A. I have
this code in an Access query. Everything works correctly except for the *
parameter. What is the proper syntax?

IIf([RECFROM]="JOB" And [PROG]="Seattle" And [SHOP] Like "*A*","Seattle"
 
J

Jeff Boyce

Maybe you could use the Like *A* in the selection criterion for that [SHOP]
field, and leave it out of the IIF() statement...

Regards

Jeff Boyce
Microsoft Office/Access MVP

djf said:
In the Field: line of the access query grid.

Jeff Boyce said:
Where are you running this code?

Regards

Jeff Boyce
Microsoft Office/Access MVP

djf said:
The wildcard search is not working for the SHOP field in the following
code.
I want to search the SHOP field for all strings that contain an A. I
have
this code in an Access query. Everything works correctly except for the
*
parameter. What is the proper syntax?

IIf([RECFROM]="JOB" And [PROG]="Seattle" And [SHOP] Like
"*A*","Seattle"
 
D

djf

Do wildcards not work in an IIF statement?

Jeff Boyce said:
Maybe you could use the Like *A* in the selection criterion for that [SHOP]
field, and leave it out of the IIF() statement...

Regards

Jeff Boyce
Microsoft Office/Access MVP

djf said:
In the Field: line of the access query grid.

Jeff Boyce said:
Where are you running this code?

Regards

Jeff Boyce
Microsoft Office/Access MVP

The wildcard search is not working for the SHOP field in the following
code.
I want to search the SHOP field for all strings that contain an A. I
have
this code in an Access query. Everything works correctly except for the
*
parameter. What is the proper syntax?

IIf([RECFROM]="JOB" And [PROG]="Seattle" And [SHOP] Like
"*A*","Seattle"
 
J

John Spencer

Wildcards do work in an IIF statement. You didn't post the entire statement,
so the problem may be caused elsewhere.

You can try using % instead of *. THe % as a wildcard would be used if you
had check Ansi 92 compatible SQL or if you were using an ADP instead of and
MDB as the backend.

IIf([RECFROM]="JOB" And [PROG]="Seattle" And [SHOP] Like "%A%","Seattle","Not
Seattle")

Otherwise, post the entire expression you are attempting to use.

John Spencer
Access MVP 2002-2005, 2007-2008
The Hilltop Institute
University of Maryland Baltimore County
Do wildcards not work in an IIF statement?

Jeff Boyce said:
Maybe you could use the Like *A* in the selection criterion for that [SHOP]
field, and leave it out of the IIF() statement...

Regards

Jeff Boyce
Microsoft Office/Access MVP

djf said:
In the Field: line of the access query grid.

:

Where are you running this code?

Regards

Jeff Boyce
Microsoft Office/Access MVP

The wildcard search is not working for the SHOP field in the following
code.
I want to search the SHOP field for all strings that contain an A. I
have
this code in an Access query. Everything works correctly except for the
*
parameter. What is the proper syntax?

IIf([RECFROM]="JOB" And [PROG]="Seattle" And [SHOP] Like
"*A*","Seattle"
 
D

djf

It didn't work with the percent signs. Here is the entire statement.

RECFROM1:
IIf([RECFROM]="FAB","FAB",IIf([RECFROM]="DEV","DEV",IIf([RECFROM]="JOB" And
[prog]="XXX","XXXX",IIf([RECFROM]="JOB" And
[prog]="SL","LAUNCH",IIf([RECFROM]="JOB" And [prog]="SEA" And [SHOP] Like
"%A%","SEA",IIf([RECFROM]="JOB" And [prog]<>"P8-A" And [prog]<>"SL" And
[prog]<>"SEA","JOB","OTHER"))))))

John Spencer said:
Wildcards do work in an IIF statement. You didn't post the entire statement,
so the problem may be caused elsewhere.

You can try using % instead of *. THe % as a wildcard would be used if you
had check Ansi 92 compatible SQL or if you were using an ADP instead of and
MDB as the backend.

IIf([RECFROM]="JOB" And [PROG]="Seattle" And [SHOP] Like "%A%","Seattle","Not
Seattle")

Otherwise, post the entire expression you are attempting to use.

John Spencer
Access MVP 2002-2005, 2007-2008
The Hilltop Institute
University of Maryland Baltimore County
Do wildcards not work in an IIF statement?

Jeff Boyce said:
Maybe you could use the Like *A* in the selection criterion for that [SHOP]
field, and leave it out of the IIF() statement...

Regards

Jeff Boyce
Microsoft Office/Access MVP

In the Field: line of the access query grid.

:

Where are you running this code?

Regards

Jeff Boyce
Microsoft Office/Access MVP

The wildcard search is not working for the SHOP field in the following
code.
I want to search the SHOP field for all strings that contain an A. I
have
this code in an Access query. Everything works correctly except for the
*
parameter. What is the proper syntax?

IIf([RECFROM]="JOB" And [PROG]="Seattle" And [SHOP] Like
"*A*","Seattle"
 
J

John Spencer

I've rewritten the expression to make it easier to understand, but I cannot
see any problem with your expression. Are you sure that SHOP contains the
letter "A" in a field. Is it possible that SHOP is a LOOKUP Field and
actually contains a value that is other then what is displayed.

RECFROM1:
IIf([RECFROM] IN ("FAB","DEV"),[RECFROM]
,IIf([RECFROM]="JOB" And [prog]="XXX","XXXX"
,IIf([RECFROM]="JOB" And [prog]="SL","LAUNCH"
,IIf([RECFROM]="JOB" And [prog]="SEA" And [SHOP] Like "*A*","SEA"
,IIf([RECFROM]="JOB" And [prog] Not In ("P8-A","SL","SEA"),"JOB","OTHER")))))

Lookup fields can contain data other than what is displayed. If you open your
table in datasheet view and the SHOP field has a combobox for data entry then
you have a lookup field. If so, post back for a discussion on why lookup
fields can be a problem.

John Spencer
Access MVP 2002-2005, 2007-2008
The Hilltop Institute
University of Maryland Baltimore County
It didn't work with the percent signs. Here is the entire statement.

RECFROM1:
IIf([RECFROM]="FAB","FAB",IIf([RECFROM]="DEV","DEV",IIf([RECFROM]="JOB" And
[prog]="XXX","XXXX",IIf([RECFROM]="JOB" And
[prog]="SL","LAUNCH",IIf([RECFROM]="JOB" And [prog]="SEA" And [SHOP] Like
"%A%","SEA",IIf([RECFROM]="JOB" And [prog]<>"P8-A" And [prog]<>"SL" And
[prog]<>"SEA","JOB","OTHER"))))))

John Spencer said:
Wildcards do work in an IIF statement. You didn't post the entire statement,
so the problem may be caused elsewhere.

You can try using % instead of *. THe % as a wildcard would be used if you
had check Ansi 92 compatible SQL or if you were using an ADP instead of and
MDB as the backend.

IIf([RECFROM]="JOB" And [PROG]="Seattle" And [SHOP] Like "%A%","Seattle","Not
Seattle")

Otherwise, post the entire expression you are attempting to use.

John Spencer
Access MVP 2002-2005, 2007-2008
The Hilltop Institute
University of Maryland Baltimore County
Do wildcards not work in an IIF statement?

:

Maybe you could use the Like *A* in the selection criterion for that [SHOP]
field, and leave it out of the IIF() statement...

Regards

Jeff Boyce
Microsoft Office/Access MVP

In the Field: line of the access query grid.

:

Where are you running this code?

Regards

Jeff Boyce
Microsoft Office/Access MVP

The wildcard search is not working for the SHOP field in the following
code.
I want to search the SHOP field for all strings that contain an A. I
have
this code in an Access query. Everything works correctly except for the
*
parameter. What is the proper syntax?

IIf([RECFROM]="JOB" And [PROG]="Seattle" And [SHOP] Like
"*A*","Seattle"
 
D

djf

I just ran my query again. I changed "%A%" to "*A*" and it's working! That's
strange, I tried it with the * many times and it didn't work. I used my
original format also, even though I like your format with the IN statements.
Thanks for you input.

John Spencer said:
I've rewritten the expression to make it easier to understand, but I cannot
see any problem with your expression. Are you sure that SHOP contains the
letter "A" in a field. Is it possible that SHOP is a LOOKUP Field and
actually contains a value that is other then what is displayed.

RECFROM1:
IIf([RECFROM] IN ("FAB","DEV"),[RECFROM]
,IIf([RECFROM]="JOB" And [prog]="XXX","XXXX"
,IIf([RECFROM]="JOB" And [prog]="SL","LAUNCH"
,IIf([RECFROM]="JOB" And [prog]="SEA" And [SHOP] Like "*A*","SEA"
,IIf([RECFROM]="JOB" And [prog] Not In ("P8-A","SL","SEA"),"JOB","OTHER")))))

Lookup fields can contain data other than what is displayed. If you open your
table in datasheet view and the SHOP field has a combobox for data entry then
you have a lookup field. If so, post back for a discussion on why lookup
fields can be a problem.

John Spencer
Access MVP 2002-2005, 2007-2008
The Hilltop Institute
University of Maryland Baltimore County
It didn't work with the percent signs. Here is the entire statement.

RECFROM1:
IIf([RECFROM]="FAB","FAB",IIf([RECFROM]="DEV","DEV",IIf([RECFROM]="JOB" And
[prog]="XXX","XXXX",IIf([RECFROM]="JOB" And
[prog]="SL","LAUNCH",IIf([RECFROM]="JOB" And [prog]="SEA" And [SHOP] Like
"%A%","SEA",IIf([RECFROM]="JOB" And [prog]<>"P8-A" And [prog]<>"SL" And
[prog]<>"SEA","JOB","OTHER"))))))

John Spencer said:
Wildcards do work in an IIF statement. You didn't post the entire statement,
so the problem may be caused elsewhere.

You can try using % instead of *. THe % as a wildcard would be used if you
had check Ansi 92 compatible SQL or if you were using an ADP instead of and
MDB as the backend.

IIf([RECFROM]="JOB" And [PROG]="Seattle" And [SHOP] Like "%A%","Seattle","Not
Seattle")

Otherwise, post the entire expression you are attempting to use.

John Spencer
Access MVP 2002-2005, 2007-2008
The Hilltop Institute
University of Maryland Baltimore County

djf wrote:
Do wildcards not work in an IIF statement?

:

Maybe you could use the Like *A* in the selection criterion for that [SHOP]
field, and leave it out of the IIF() statement...

Regards

Jeff Boyce
Microsoft Office/Access MVP

In the Field: line of the access query grid.

:

Where are you running this code?

Regards

Jeff Boyce
Microsoft Office/Access MVP

The wildcard search is not working for the SHOP field in the following
code.
I want to search the SHOP field for all strings that contain an A. I
have
this code in an Access query. Everything works correctly except for the
*
parameter. What is the proper syntax?

IIf([RECFROM]="JOB" And [PROG]="Seattle" And [SHOP] Like
"*A*","Seattle"
 
D

djf

I also checked the SHOP field and it is not a look up field.

John Spencer said:
I've rewritten the expression to make it easier to understand, but I cannot
see any problem with your expression. Are you sure that SHOP contains the
letter "A" in a field. Is it possible that SHOP is a LOOKUP Field and
actually contains a value that is other then what is displayed.

RECFROM1:
IIf([RECFROM] IN ("FAB","DEV"),[RECFROM]
,IIf([RECFROM]="JOB" And [prog]="XXX","XXXX"
,IIf([RECFROM]="JOB" And [prog]="SL","LAUNCH"
,IIf([RECFROM]="JOB" And [prog]="SEA" And [SHOP] Like "*A*","SEA"
,IIf([RECFROM]="JOB" And [prog] Not In ("P8-A","SL","SEA"),"JOB","OTHER")))))

Lookup fields can contain data other than what is displayed. If you open your
table in datasheet view and the SHOP field has a combobox for data entry then
you have a lookup field. If so, post back for a discussion on why lookup
fields can be a problem.

John Spencer
Access MVP 2002-2005, 2007-2008
The Hilltop Institute
University of Maryland Baltimore County
It didn't work with the percent signs. Here is the entire statement.

RECFROM1:
IIf([RECFROM]="FAB","FAB",IIf([RECFROM]="DEV","DEV",IIf([RECFROM]="JOB" And
[prog]="XXX","XXXX",IIf([RECFROM]="JOB" And
[prog]="SL","LAUNCH",IIf([RECFROM]="JOB" And [prog]="SEA" And [SHOP] Like
"%A%","SEA",IIf([RECFROM]="JOB" And [prog]<>"P8-A" And [prog]<>"SL" And
[prog]<>"SEA","JOB","OTHER"))))))

John Spencer said:
Wildcards do work in an IIF statement. You didn't post the entire statement,
so the problem may be caused elsewhere.

You can try using % instead of *. THe % as a wildcard would be used if you
had check Ansi 92 compatible SQL or if you were using an ADP instead of and
MDB as the backend.

IIf([RECFROM]="JOB" And [PROG]="Seattle" And [SHOP] Like "%A%","Seattle","Not
Seattle")

Otherwise, post the entire expression you are attempting to use.

John Spencer
Access MVP 2002-2005, 2007-2008
The Hilltop Institute
University of Maryland Baltimore County

djf wrote:
Do wildcards not work in an IIF statement?

:

Maybe you could use the Like *A* in the selection criterion for that [SHOP]
field, and leave it out of the IIF() statement...

Regards

Jeff Boyce
Microsoft Office/Access MVP

In the Field: line of the access query grid.

:

Where are you running this code?

Regards

Jeff Boyce
Microsoft Office/Access MVP

The wildcard search is not working for the SHOP field in the following
code.
I want to search the SHOP field for all strings that contain an A. I
have
this code in an Access query. Everything works correctly except for the
*
parameter. What is the proper syntax?

IIf([RECFROM]="JOB" And [PROG]="Seattle" And [SHOP] Like
"*A*","Seattle"
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Top