Code to search 'any part of field'

A

AMH

I use a form to search a text field in a query

The SQL view of the query looks like this

SELECT qryMainRefList.YR, qryMainRefList.TI, qryMainRefList.SO,
qryMainRefList.AU, qryMainRefList.[IN], qryMainRefList.AB
FROM qryMainRefList
WHERE (((qryMainRefList.AU)=[Forms]![frmSearch]![txtAU]))
ORDER BY qryMainRefList.YR DESC;

The problem is that when it searchs for the input from
[Forms]![frmSearch]![txtAU] it looks for a whole field value
I need to look for any part of the field and can not do it.
Thanks in advance

AMH
 
J

John Spencer (MVP)

Look up the LIKE operator and Wildcard characters.

You probably need to end up with something like the following.

SELECT qryMainRefList.YR, qryMainRefList.TI, qryMainRefList.SO,
qryMainRefList.AU, qryMainRefList.[IN], qryMainRefList.AB
FROM qryMainRefList
WHERE (((qryMainRefList.AU) LIKE "*" & [Forms]![frmSearch]![txtAU] & "*"))
ORDER BY qryMainRefList.YR DESC;

By the way, thanks for posting your SQL string. It is much easier to understand
the problem and suggest solutions when this is done.
 
A

AMH

Thank you very much, it works.
Thanks again for the time you give for unexperienced users like me.
 

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

Top