Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

"Like" Operator for criteria 1

Status
Not open for further replies.

SERT1

Programmer
Sep 13, 2001
33
CA
I'm having trouble getting the right syntax for a "like" criteria that needs to get information from a text box from a form. The syntax I've tried is:

Like "*" & ([Forms]![fLocCd]![txtLocCd]) & "*"
Like '& [Forms]![fLocCd]![txtLocCd]& '
Like [Forms]![fLocCd]![txtLocCd]

Nothing works.

Can anyone help?
 
for a string value try:
Like "'*" & [Forms]![fLocCd]![txtLocCd]& "*'"

for a numeric try:

like "*" & [Forms]![fLocCd]![txtLocCd] & "*"

Nick
 
I'm assuming that is a single quote followed by a double quote for the text string?
 
It is double single * double criteria double * single double

Or copy and paste it.

Nick
 
That doesn't bring back any information. If I hard code the criteria in, there's a lot of records, so I know the information is there. Any other suggestions? It is a string value.
 
Sorry, I think i typed it in slightly wrong. Try:
Like "*'" & [Forms]![fLocCd]![txtLocCd]& "'*"

That should definatley work (I think).

Nick
 
Hi!

What event procedure are you putting this code in? And could you post all of the procedure?

Jeff Bridgham
 
This is just a criteria line in a query. All I need it to do it read a text box that will have had information typed into it (i.e. PROC.EQUP.PART). I need to have it with the "like" operator with a "*" wildcard in order to bring back any records that have that code in it. If I hard code the criteria for the field, the information comes back no problem:

i.e. Like 'PROC.EQUP.PART*'

When I try to run the query with that information from an unbound text box on a small form, nothing comes back.

Does that explain it a bit better?
 
Did you try
Like "*" & [Forms]![fLocCd]![txtLocCd] & "*"? This is in the criteria of a query?
 
If it's in the criteria box of a query, your very first example will work:

Code:
Like "*" & [Forms]![fLocCd]![txtLocCd] & "*"

Single quotes are not needed.....
 
Thank you so much. Nickjar2 - you suggested that one in the first response for a numeric field, but since this is a text field, I never even tried it. I just tried the one for the string field.

Thank both of you for your help, I got the proper information back.

 
Hi!

What I was asking is how is the query called from the form and what code is involved with opening the query? Or do you go back to the Db window and open it from there? I'm asking because Nick is giving you good syntax so I thought that the problem may lie somewhere else.

Jeff Bridgham
 
I think I must be going mad because I am sure I always use single quotes when using a string variable.

Nick

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top