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

VB6, SQL and the LIKE operator 2

Status
Not open for further replies.

HaworthBantam

Programmer
Jan 31, 2002
132
GB
I am creating a sql string....

MySQL = "SELECT * FROM tblRemissions WHERE CustomerName LIKE '*" & strVariable & "*'" & " ORDER BY RemissionID"

strVariable is as it suggests, is a string variable.

If I use a sql string where the whole name is known....

MySQL = "SELECT * FROM tblRemissions WHERE CustomerName = " & strVariable & " ORDER BY RemissionID"

....it works.

Is any kind soul out there able to point out my mistake ?

Thanks.
 
Perhaps you are using ADO reference instead of DAO.
In that case, the wildcard character is %
If this works:
MySQL = "SELECT * FROM tblRemissions WHERE CustomerName LIKE '%" & strVariable & "%'" & " ORDER BY RemissionID"

Then you have ADO reference...

Cheers,
makeItSo

Andreas Galambos
EDP / Technical Support Specialist
(andreas.galambos@bowneglobal.de)
HP:
 
SQL wildcard operator is '%' not '*' . Your line should read:
MySQL = "SELECT * FROM tblRemissions WHERE CustomerName LIKE '%" & strVariable & "%'" & " ORDER BY RemissionID"

________________________________________________________________
If you want to get the best response to a question, please check out FAQ222-2244 first

'People who live in windowed environments shouldn't cast pointers.'
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top