Click to See Complete Forum and Search --> : Loopy


bloke
05-30-2003, 06:13 AM
Can someone please take a quick look at this and tell me why a record that meets the conditions to be excluded still appears.

It is probably something very obvious that I can't see for looking.

<%
If rscorres.EOF Then%>
<tr bgcolor="#ffffff" class="doctitle" align="center">
<td colspan="4">Sorry, there are no items which match your search</td>
</tr>
<%Else

Do While Not rscorres.EOF 'loop through records until end of file

If rscorres("sensitive") = true Then 'if the current record has a field called sensitive with a value of True then...

'which it is for the record in question

'..check this

If strsensitive <> rscorres("sens_name") Then 'if the network logon userid (determined earlier) does not equal the corresponding value in the current record then....

'which is true in this case

rscorres.movenext '...skip this record

End If

If rscorres.eof Then 'if there are no more records then....

'which should be ignored as there are other records to write

Exit Do '....end the loop

End If

End If

'....if the record is not sensitive (which it is) then......

'....set variable values from record set values...

intDay = DAY(rscorres("date_logged"))
intMonth = MONTHNAME(MONTH(rscorres("date_logged")))
intYear = YEAR(rscorres("date_logged"))

strDate = intDay & "&nbsp;" & intMonth & "&nbsp;" & intYear

strURL = "documents/loaded/" & rscorres("document_name")

'...then write the values to the page ..AND THE SODDING RECORD APPEARS HERE!!
%>
<tr bgcolor="#ffffff" onmouseover="this.bgColor = '#C0C0C0';window.status=''" onmouseout="this.bgColor = '#ffffff'" class="doctitle">
<td align="center"><a href="javascript:newWindow('<%=strURL%>')"><img src="../images/magnify.gif" border="0"></a></td>
<td><%=replace(rscorres("contract_no"), "_", "/")%></td>
<td><%=rscorres("document_name")%></td>
<td><%=strDate%></td>
</tr>
<%

rscorres.movenext 'move on to next record

Loop%>


Cheers

DaiWelsh
05-30-2003, 07:25 AM
Ok, firstly you have tortured the logic of this loop by adding the extra movenext/exit do in the middle, I would suggest instead that in this case you just skip the displays and let the loop move on to the next record by itself.

That is

Do While Not rscorres.EOF 'loop through records until end of file
If rscorres("sensitive") = true Then 'if the current record has a field called sensitive with a value of True then...
'which it is for the record in question
'..check this
If strsensitive <> rscorres("sens_name") Then 'if the network logon userid (determined earlier) does not equal the corresponding value in the current record then....
'which is true in this case
SET A FLAG HERE INSTEAD
End If
End If
if (FLAG SET) then
'....if the record is not sensitive (which it is) then......
'....set variable values from record set values...
intDay = DAY(rscorres("date_logged"))
intMonth = MONTHNAME(MONTH(rscorres("date_logged")))
intYear = YEAR(rscorres("date_logged"))
strDate = intDay & " " & intMonth & " " & intYear
strURL = "documents/loaded/" & rscorres("document_name")
'...then write the values to the page ..AND THE SODDING RECORD APPEARS HERE!!
%>
<tr bgcolor="#ffffff" onmouseover="this.bgColor = '#C0C0C0';window.status=''" onmouseout="this.bgColor = '#ffffff'" class="doctitle">
<td align="center"><a href="javascript:newWindow('<%=strURL%>')"><img src="../images/magnify.gif" border="0"></a></td>
<td><%=replace(rscorres("contract_no"), "_", "/")%></td>
<td><%=rscorres("document_name")%></td>
<td><%=strDate%></td>
</tr>
<%
end if
rscorres.movenext 'move on to next record
Loop%>

Anyway, that aside, have you actually verified that the things are true which have indicated are true in the comments, or are you just going on the data you see in the database? If the latter, instead of

If rscorres("sensitive") = true

try

If rscorres("sensitive").value = true

as this is more correct and may actually be your problem.

Failing that try putting debug response.write values into your code to verify which path it is taking and hence which statement is not behaving as you expect.

Proabbly one of the two ifs is not coming out as you expect due to datatypes or incorrect values.

HTH,

Dai

bloke
05-30-2003, 07:30 AM
Hmm, ok I'll try just skipping the display.

I've done all of the other things you suggest and know that details to be correct. The most annoying thing about this is that it appears to be skipping all but one record, and only, it seems, when it feels like it.

I think I've just tied myself up in knots. I'll see how I get on.

Cheers for you help Dai

bloke
05-30-2003, 08:37 AM
I bow down to thee oh great one!

;-)

bloke
06-02-2003, 05:07 AM
...as opposed to being off my box!

A slight amendment and all is happy in the world of bloke!

If (rscorres("sensitive") = true and strsensitive = rscorres("sens_name")) _
OR rscorres("sensitive") <> true Then


Thanx for your help.