Results 1 to 3 of 3
  1. #1
    Join Date
    Jan 2004
    Posts
    38

    Unanswered: Do Until blah then stop

    I am having trouble with the following code!

    Set RSB = Conn.Execute("SELECT * FROM PetObituarys WHERE username = '" & Session("username") & "' order by Expired asc")

    do until RSB.EOF
    IF CDate(RSB("Expired")) <= (Date+7) OR RSB("Approved") = 0 Then
    Response.write "<Font Color=Red> ATTN:"
    End If
    RSB.Movenext
    Loop


    The above code outputs the following

    <Font Color=Red> ATTN:<Font Color=Red> ATTN:<Font Color=Red> ATTN:<Font Color=Red> ATTN:</Font></Font></Font></Font>

    and I only want it to output
    <Font Color=Red> ATTN:</Font>

    no matter how many records have the criteria

    Basically what is missing to tell it to stop the loop after finding the first record that matchs the criteria

  2. #2
    Join Date
    Jan 2004
    Posts
    38
    As always I just have to post the question to get the answer!! Argh

    I realized that all I had to do was add

    Dim NumChk
    do until RSB.EOF OR NumChk = 1
    IF CDate(RSB("Expired")) <= (Date+7) OR RSB("Approved") = 0 Then
    Response.write "<Font Color=Red> ATTN:"
    NumChk = NumChk + 1
    End If
    RSB.Movenext
    Loop

    and it stopped once I hit NumChk = 1 lol

    Well Thanks for reading

  3. #3
    Join Date
    Dec 2003
    Posts
    454
    The other way is to use the statement Exit Do

    <%
    Do until RSB.EOF
    IF CDate(RSB("Expired")) <= (Date+7) OR RSB("Approved") = 0 Then
    Response.write "<Font Color=Red> ATTN:"
    Exit Do
    End If
    RSB.Movenext
    Loop
    %>

Posting Permissions

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