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!

test problem (IF THEN or StrComp)?

Status
Not open for further replies.

Kinl

Programmer
Mar 19, 2001
168
US
I'm using ADO, at the same time I"m trying to loop through a record set. At this time when I try to test if a Fname, Lname and Zipcode are in the database, by comparing the rs("fname") = ls_fname variable. Here is the code segment that I use, and it seems to fail out. I dunno what I might have done wrong.
-----------------------------

If rsCount(0) <> 0 THEN
rs.movefirst
Do Until rs.EOF
IF (rs(&quot;fname&quot;) = ls_fname) AND (rs(&quot;lname&quot;) = ls_lname) AND (rs(&quot;zip&quot;) = ls_zip) THEN
MSG = &quot;You can only enter the contest once. Thank you.&quot;
Exit Do
End If
rs.movenext
Loop
---------------------------------

THe problem is that it never breaks out of the loop. It should if any of the tests proves false. Can anyone see where I&quot;m going wrong?

Thanx,

Donn
 
Two things

1. Use Trim and cstr function to ensure no spaces in the input fields and to ensure you're making comparison for the same data type.

ie Trim(cstr(rs(&quot;fname&quot;)))=Trim(cstr(Isname))

2.Why don't use SELECT COUNT...WHERE Trim(cstr(rs(&quot;fname&quot;)))=Trim(cstr(Isname))......

It'll be much quicker than going through a loop.

Regards
 
It was the Trim that solved my problem.

Thanx alot! I really appreciate the help!
donn
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top