dhuang
asked on
How to filter using select statement with like
how can I get this to work in VB
Filterinfo = "%123%" 'match 123
Data1.RecordSource = "select * from [Customer] where [AccountNo] like '" & filterInfo & "'"
Filterinfo = "%123%" 'match 123
Data1.RecordSource = "select * from [Customer] where [AccountNo] like '" & filterInfo & "'"
More clearly:
FilterInfo = "'" & 123 & "'"
Data1.RecordSource = "SELECT * FROM Customer WHERE AccountNo LIKE " & FilterInfo
FilterInfo = "'" & 123 & "'"
Data1.RecordSource = "SELECT * FROM Customer WHERE AccountNo LIKE " & FilterInfo
Also, what database are you using? If it's access, the %'s from the earlier comment should be astericks.
ASKER
Kamall: Sorry, I can't give the points to you.
1) The source code gives error, b'cos of the wrong SQL command.
You need the ' after the LIKE
eg. Just like the one in my example.
1) The source code gives error, b'cos of the wrong SQL command.
You need the ' after the LIKE
eg. Just like the one in my example.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
NB. If you are using the Access, use the * instead of the % for matching.
Data1.RecordSource = "SELECT * FROM Customer WHERE AccountNo LIKE " & Text & " "