like statement in SQL query in Access

I

ITHELP

I am using a form to find some data from a table. In the table are
fields such as Client name, job number, and job description. I built a
query using a SQL statement through the 'Record source' for the form. I
can get the query to work if I type in the Client name exactly as it is
in the table. However, I want to be able to use a like statement to
expand my search and find all records with a certain word or year in
it. How can I get this to work?
Currently the SQL statement looks like: SELECT [CD Query].* FROM [CD
Query] WHERE ((([CD Query].[PROJECT NUMBER])=Forms!CDtest!scanned));
CD Query is the name of the Query, I'm searching by project number,
CDtest is the name of the form, and scanned is the name of the text box
where I enter what I'm looking for.
Any help is greatly appreciated. Thanks!
 
A

Aaron Bertrand [SQL Server MVP]

I assume you submit the form, and aren't trying to do this as the user is on
the page.

sql = "SELECT * FROM [CD Query] WHERE [Project Number] LIKE '%" &
replace(request.form("scanned"), "'", "''") & "%'"

You really should consider better object names. Why the spaces? Do you
like typing square brackets all over the place? And try to avoid SELECT *
in production code.

Also, you might find this page useful:
http://www.aspfaq.com/2183
 

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

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top