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

"loop without do" error with If condition

Status
Not open for further replies.

werosen1

Programmer
Mar 30, 2006
16
US
I am running the following in an ASP page and it works perfectly:

<%
dim Rdate
dim PrevRdate

Set conn = server.createobject("adodb.connection")
conn.connectionstring = "DRIVER={Microsoft Access Driver (*.mdb)}; DBQ=C:\tradersreportsdata\reportevents.mdb;pwd=matrix"
conn.Open
Set rs=Server.CreateObject("ADODB.recordset")
rs.open "SELECT FORMAT(rTime ,'h:nnam/pm') as fTime,rDate,rName FROM reports WHERE (((Format(rDate,'yyyy-ww'))=Format(Date(),'yyyy-ww')));", conn

do until rs.EOF

Rdate = rs("rDate")

response.write (Rdate & rs("rName") & rs("fTime") &"<BR>")

rs.movenext
loop

rs.close
conn.close
Set conn = Nothing
%>

I want the Rdate value to be set to nothing, and not the value from the query, if the current record has the same value as the previous record's value, so I changed:

Rdate = rs("rDate")

to:

PrevRdate = Rdate

If PrevRdate <> rs("rDate") Then
Rdate = rs("rDate")
Else
Rdate = ""

so that the new code is:

<%
dim Rdate
dim PrevRdate

Set conn = server.createobject("adodb.connection")
conn.connectionstring = "DRIVER={Microsoft Access Driver (*.mdb)}; DBQ=C:\tradersreportsdata\reportevents.mdb;pwd=matrix"
conn.Open
Set rs=Server.CreateObject("ADODB.recordset")
rs.open "SELECT FORMAT(rTime ,'h:nnam/pm') as fTime,rDate,rName FROM reports WHERE (((Format(rDate,'yyyy-ww'))=Format(Date(),'yyyy-ww')));", conn

do until rs.EOF

Rdate = rs("rDate")

response.write (Rdate & rs("rName") & rs("fTime") &"<BR>")
Move to the Next Record in the database

rs.movenext
loop

rs.close
conn.close
Set conn = Nothing
%>

This returns 'loop' without 'do'.

Can anyone tell me what I'm doing wrong?
 
Sorry, I just saw my cut and paste error where I dropped the 'End If'
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top