'Like' operator no working in vb

sasa
02-07-2002, 12:41 PM
Hi all, please take a look at my query, what wrong with it? how come I can use the LIKE operator from vb to access97? Please help.Thanks!

sql = "SELECT * FROM RSUser WHERE RS LIKE ' " & Me.txtSearchTextFrom.Text & " ' & "*" &;"

Rhoarke
02-07-2002, 01:02 PM
well for one your " and ' are kinda screwy. Sql would want it something like this...dunno about m$ft

sql = "SELECT * FROM RSUser WHERE RS LIKE ' " & Me.txtSearchTextFrom.Text & " ' " & "*" & ";"

sasa
02-07-2002, 01:05 PM
I am sorry I meant

sql = "SELECT * FROM RSUser WHERE RS LIKE ' " & Me.txtSearchTextFrom.Text & " ' & "*" & ;"

reboot
02-07-2002, 01:09 PM
ADO or DAO? SQL Server or Access?

[edit] oops, you already said access. [edit]

Rhoarke
02-07-2002, 01:09 PM
Correction:

SQL would want it like this:

sql = "select * from table where field like ' " & text1.text & "%' "

m$ft should be close, though I'm not sure about the wildcard char...

sasa
02-07-2002, 02:31 PM
ADO/ACCESS

reboot
02-07-2002, 02:57 PM
Use '%' for your wildcard instead of '*', like Rhoarke said.

sasa
02-07-2002, 03:04 PM
:( it didn't work

reboot
02-07-2002, 03:05 PM
Explain what 'didn't work' means... it always works for me. Maybe post a piece of your code where it's not working...

[edit]

If you're using the SQL you posted earlier

sql = "SELECT * FROM RSUser WHERE RS LIKE ' " & Me.txtSearchTextFrom.Text & " ' & "*" & ;"

you need to change that to

sql = "SELECT * FROM RSUser WHERE RS LIKE '" & Me.txtSearchTextFrom.Text & "%'"

[edit]

sasa
02-07-2002, 03:10 PM
sql = "SELECT * FROM RRHEADER WHERE LOCATION LIKE ' " & Me.txtSearchTextFrom.Text & "*';"

Before with the "*", it will at least return some records, right now with the "*" it is not return any record at all... if it is working right, it should return all of the record(s) that have the me.txtSearchTextFrom.text as the first part of the text right? I tested in Access, it is working just fine, but if I want to pass this from VB, it won't work, please help. Thanks!

Flyguy
02-07-2002, 03:14 PM
Reboot and Keltus adviced you to use the "%" did you try this???

reboot
02-07-2002, 03:15 PM
try this

sql = "SELECT * FROM RRHEADER WHERE LOCATION LIKE '" & Me.txtSearchTextFrom.Text & "%'"

a) you can't use * with ADO, the wildcard for LIKE is %

b) watch out for spaces, it doesn't trim them for you, you had LIKE ' " & Me.txtSearchTextFrom.Text, which would translate to LIKE ' location'. It's going to try to match ' location' and not 'location'. See what I mean? And in the earlier version, you had a space AFTER the wildcard also.

sasa
02-07-2002, 03:16 PM
Thanks everyone, % is the answer.

EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum