...

View Full Version : Do Until blah then stop



Crash1hd
01-01-2005, 12:50 PM
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

Crash1hd
01-01-2005, 01:29 PM
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

glenngv
01-03-2005, 06:53 AM
Or you can just put Exit Do to break out of the loop.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum