Search for value in query output

santosm
3StarLounger
Posts: 253
Joined: 19 Apr 2010, 09:01
Location: Indiana, USA

Search for value in query output

Post by santosm »

Hi All,
I have a query that works when I put in a criteria something like this:

Like micro*

It returns the records I want. However, I want to run this from a form text field after update event and I am getting a syntax error. I am sure there is a set way I need to enclose the term micro*.

Code: Select all

Forms!fContracts_Queue!Child1.Form.RecordSource = "select * from qContracts where (qContracts.NAME_24) = micro*"
Thanks,
Mark
Thanks,
Mark

User avatar
HansV
Administrator
Posts: 78651
Joined: 16 Jan 2010, 00:14
Status: Microsoft MVP
Location: Wageningen, The Netherlands

Re: Search for value in query output

Post by HansV »

As you mention yourself, you must use Like if you want to use wildcards such as * or ?
And text values must be enclosed in quotes. Since the entire record source is already enclosed in double quotes, you can use single quotes around micro*:

Code: Select all

Forms!fContracts_Queue!Child1.Form.RecordSource = "select * from qContracts where NAME_24 Like 'micro*'"
Best wishes,
Hans

santosm
3StarLounger
Posts: 253
Joined: 19 Apr 2010, 09:01
Location: Indiana, USA

Re: Search for value in query output

Post by santosm »

Hi Hans,
Thanks again! I used this to finally get the search box where i want it:

Code: Select all

        sSearch = "'*" & Me.Text235 & "*'"
        Forms!fContracts_Queue!Child1.Form.RecordSource = "select * from qContracts where (qContracts.NAME_24) like " & sSearch
Thanks,
Mark