Searching a field from a Form using a wildcard (1 Viewer)

PRD

Registered User.
Local time
Today, 08:26
Joined
May 18, 2011
Messages
72
I am trying to search a field in a record using the ‘Like’ keyword (e.g. Like “*Smith*”). When I use this syntax in a query it works perfectly (finding all records that have 'Smith' somewhere in the field) but when I try to run this same query from an Access Form I get no records found (I created a text field on a Form which runs the query after passing - Like “*Smith*” -to the query).

So my question is, how can I search a field in a Table using the 'Like' keyword (or any wildcard) from a Form? Thank you for your time.
 

boblarson

Smeghead
Local time
Today, 05:26
Joined
Jan 12, 2001
Messages
32,059
You can't pass Like "*Smith*" to the query using the form control. It won't recognize it because it is then being passed as a string value. You would need to set up the criteria IN THE QUERY to be:

Like "*" & [Forms]![YourFormNameHere]![YourTextBoxNameHere] & "*" OR [Forms]![YourFormNameHere]![YourTextBoxNameHere] Is Null

(the second part about the Is Null will take care of it if no criteria is passed).
 

PRD

Registered User.
Local time
Today, 08:26
Joined
May 18, 2011
Messages
72
Bob -

Awesome, thank you! I didn't think of concatenation, can't wait to give it a try. The more I delve into the workings of MS Access the more impressed I am of what it can actually do. Thanks again.
 

PRD

Registered User.
Local time
Today, 08:26
Joined
May 18, 2011
Messages
72
Bob -

It worked like a charm, thank you again for your help, it is much appreciated!
 

Users who are viewing this thread

Top Bottom