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

Problems with If Statement 1

Status
Not open for further replies.

Castanz

Programmer
Apr 5, 2002
61
US
Hi Everyone,
I am stuck on this (what should be easy) task.

I am retrieving "MealCard" from a calling forms page. Then I want to match to check for duplicates by comparing what was entered on the form with what is in the data base.

The nearest I can tell is that the data types might be different because "MealCardData = MealCardvalue" never tests to be true.


Code:
Alreadyexists = FALSE
MealCardvalue = Request("MealCard")
LNamevalue = Request("LastName")

	While Not RS.EOF
	   MealCardData = RS("MealCard")
	 
	    If  MealCardData = MealCardvalue  Then
		Alreadyexists = TRUE
		Response.write "<p>Alreadyexists = " & Alreadyexists & "</p>"
	    Else
		Response.write "<p>Alreadyexists Else = " & Alreadyexists & "</p>"
	    End If
		
		Response.write "<p>MealCardData = " & MealCardData & "</p>"
		Response.write "<p>MealCardvalue = " & MealCardvalue & "</p>"
	   RS.movenext
	wend

Can anyone tell me what I am doing wrong?

Thanks in advance,
Al :)
 
If [!]Trim([/!]MealCardData[!])[/!] = [!]Trim([/!]MealCardvalue[!])[/!] Then

-George

"The great things about standards is that there are so many to choose from." - Fortune Cookie Wisdom
 
If it is possible the column MealCard column in will contain the value Null then do this:
[tt]
MealCardData = RS("MealCard") [red]& ""[/red]
[/tt]

By adding an empty string you can avoid an error that may result when passing Null to the Trim() method.
 
Once AlreadyExists is set to True, it will display True for every subsequent record because it's not reset to False at the beginning of the loop.

I'd recommend:
Code:
If  MealCardData = MealCardvalue  Then
  Response.write "<p>Already exists = " & True & "</p>"
Else
  Response.write "<p>Already exists = " & False & "</p>"
End If

Lee
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top