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

String comparison

Status
Not open for further replies.

malladisk

Programmer
Jun 14, 2001
69
US
Hi,
I have a Record Set object and I'm trying to find a particular record using the first name and last name (which are fields in the recordset).
I have FirstName = "John" and LastName = "Doe" and I'm trying to move thru the recordset using the movenext method and comparison using the line:
If objRS("FirstName") = FirstName And objRS("LastName") = LastName Then 'Do Something
But I can't get a result, even though John Doe is present in the table, this If stmt is returning false. I tried two nested If's as well but didn't work.
Thanks,
Sashi
 
If objRS("FirstName") = rtrim(FirstName) And &_
objRS("LastName") = rtrim(LastName)

???? br
Gerard
 
Try trimming the REcordset field

IF TRIM(objRS("FirstName")) = TRIM(FirstName) And & _
TRIM(objRS("LastName")) = TRIM(LastName) THEN
'Do some cool stuff
Else
'Do some other cool stuff
END IF

I had a problem with this as well. THe problem ended up being that the recordset had added whitespace after the field. So if I had a varchar of 20, and I put "bob" in it. It would then return "bob " .. or something of that nature.
The TRIM() function fixed it for me.
Hope it works for you.

nnod
 
Nnod,
That's exactly what happened. In the database, the names are 20 chars long, both first and last. So I needed to right trim the names in the recordset and then it worked fine.
Thanks, guys,
Sashi
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top