|
-
Oct 25th, 2011, 12:39 PM
#1
Thread Starter
Addicted Member
[RESOLVED] trouble with LIKE operator
i am new to the LIKE operator. i am setting up a search in an access database so the user can search a partial string, eg search for "White" and find all records with the word white as part of the field contents.
this works when i make a query inside access but i cannot duplicate it in VB6 when connected to the same database table. i get an empty recordset
what am i doing wrong?
Code:
Private Sub Form_Load()
Set CNSKUList = New ADODB.Connection
CNSKUList.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;" & _
"Data Source=" & WorkFlowDatabasePath & ";" & "user id=admin;password=;"
CNSKUList.Open
Set RstSKUList = New ADODB.Recordset
end sub
Private Sub SearchButton_Click()
RstSKUList.Open "select * from SKULIST WHERE Description LIKE ' * White * ' ", CNbatchtable, adOpenKeyset, adLockOptimistic, adCmdTableDirect
Set SKUListMSHFlexGrid.DataSource = RstSKUList
RstSKUList.Close
end sub
Last edited by daveinarmstrong; Oct 25th, 2011 at 12:47 PM.
-
Oct 25th, 2011, 12:48 PM
#2
Re: trouble with LIKE operator
Try with no spaces
and, try with % instead of *
JG
... If your problem is fixed don't forget to mark your threads as resolved using the Thread Tools menu ...
-
Oct 25th, 2011, 01:10 PM
#3
Thread Starter
Addicted Member
Re: trouble with LIKE operator
Thanks, this works.
what if i was using a variable for the search string? i am getting no data using a variable.
Code:
dim MyVariable as string
MyVariable = "White"
LIKE '%MyVariable%' ",
-
Oct 25th, 2011, 01:35 PM
#4
Re: trouble with LIKE operator
"LIKE '%" & MyVariable & "%' "
-
Oct 25th, 2011, 01:36 PM
#5
Re: trouble with LIKE operator
Just like other times you want to append a variable to a string, use the variable rather than a piece of text which happens to be the same as the variable name.
For more information, see the article How can I put the value of a variable/control into my SQL statement? from our Database Development FAQs/Tutorials (at the top of this forum)
edit: I was slow!
-
Oct 25th, 2011, 02:33 PM
#6
Thread Starter
Addicted Member
Re: trouble with LIKE operator
this works, thanks.
Code:
LIKE '%" & MyVar & "%'
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|