Link to home
Start Free TrialLog in
Avatar of dhuang
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 & "'"
Avatar of Dr. Kamal Mehdi
Dr. Kamal Mehdi
Flag of Greece image

Text = "'" & 123 & "'"
Data1.RecordSource = "SELECT * FROM Customer WHERE AccountNo LIKE " & Text & " "
More clearly:
FilterInfo = "'" & 123 & "'"
Data1.RecordSource = "SELECT * FROM Customer WHERE AccountNo LIKE " & FilterInfo
Avatar of dochopper
dochopper

Also, what database are you using?  If it's access, the %'s from the earlier comment should be astericks.  
Avatar of dhuang

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.
ASKER CERTIFIED SOLUTION
Avatar of terencebeh
terencebeh

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of dhuang

ASKER

NB. If you are using the Access, use the * instead of the % for matching.