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 Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Is it possible to use a variable when using LIKE in SQL? 1

Status
Not open for further replies.

notageek7

Technical User
Jan 23, 2004
54
US
I've got a listbox that requeries after a user chooses a value from a combo box. In my sql statement I'm using LIKE in my WHERE clause because the records have a field with multiple values so I'm needing to search for a string within the field like 'CP'. My question is can I use a variable in the place of the hardcoded value...like 'CP'?

this sql statemenet is what I've been using:
"SELECT * FROM Orders WHERE ERRORCODES = '" & Me.cbxOrderErrors & "'"

can I incorporate a variable or the combobox value like above into this sql statement:
"SELECT * FROM Orders WHERE ERRORCODES LIKE '%CP%'
 
Well, why don't you do it like this:
"SELECT * FROM Orders WHERE ERRORCODES LIKE '%" & Me.cbxOrderErrors & "%'"

... except whatever variable you like in place of Me.cbxOrderErrors

 
Thank you for your help....that worked great. It seemed too straightforward, I was going to try that but.....lol.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top