Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    Regular Coder
    Join Date
    Jul 2002
    Location
    51° 03' -78" N -114° 05' 72" W
    Posts
    617
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Do Until blah then stop

    I am having trouble with the following code!

    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
    Regular Coder
    Join Date
    Jul 2002
    Location
    51° 03' -78" N -114° 05' 72" W
    Posts
    617
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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
    Supreme Master coder! glenngv's Avatar
    Join Date
    Jun 2002
    Location
    Philippines
    Posts
    11,043
    Thanks
    0
    Thanked 251 Times in 247 Posts
    Or you can just put Exit Do to break out of the 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
    •