Accessing a variable in a Do Loop

Results 1 to 3 of 3

Thread: Accessing a variable in a Do Loop

  1. #1
    Join Date
    Dec 1969

    Default Accessing a variable in a Do Loop

    I&#039;m using a Do Loop to cycle through a table and compare the value of a variable to the value of one of the fields. Oddly, the comparison works fine if I manually assign the value of the variable (e.g. "ContactKey = 11") but the comparison fails if I use the ContactKey = Request.form("ContactKey") method. *However* (and this is where it gets weird), the ContactKey = Request.Form("ContactKey") is successful at retrieving the value from the previous page. I&#039;ve verified that this is true by doing a "Response.Write ContactKey" outside of the Do Loop. No problems in that event. This problem is really blowing my mind. Any help would be tremendously appreciated. Here&#039;s the code:<BR><BR>ContactKey = Request.Form("ContactKey")<BR><BR>objRS.MoveFirst< BR>Do While not objRS.EOF<BR> If objRS.Fields("ContactID") = ContactKey Then<BR> varContactName = objRS.Fields("FirstName") & " " & objRS.Fields("LastName")<BR> End If<BR> objRS.MoveNext<BR>Loop<BR><BR>Many, many thanks in advance!

  2. #2
    Join Date
    Dec 1969

    Default Data Types

    When you pull it out of the querystring, contactkey is a string. You need to convert it to a number using cLng() or cDbl() depending on what type of number it is... then your comparisons will work.

  3. #3
    Join Date
    Dec 1969

    Default RE: Accessing a variable in a Do Loop

    ContactKey = CLNG(Request.Form("ContactKey"))

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts