Nick G
Nick G

Reputation: 1229

How do i check if i'm on the last record of an ADO Recordset?

how do i know if i'm on the last record of the recordset. my loop is as follows;

<%do while (adoRsTrade.AbsolutePage = iPageCurrent) and (not adoRsTrade.EOF)
NewRep = adoRsTrade("calIncludedRep")%>

i have a lot of code in between but this if statement is what matters, it displays subtotals of the data being presented as long as the CurRep <> NewRep which means that is is now onto the next persons set of data

if (CurRep <> NewRep or FirstTime="T" and (not adorsTrade.BOF)) then
  If FirstTime <> "T" then%>
      <TR>
        <td>
            <table class='FontStandardMinus1' border=0 cellPadding=0 align='left' cellSpacing=0 width="100%" bgcolor='#ffffff'>
                 <TR>
                    <td width="59%" align="left"><b>SubTotals<!-- for <%Response.Write(CurRep) %>-->:</b></td>
                    <td width="10%" valign=top align=right><%=FormatNumber(totPrincipal,2)%></td>
                    <td width="7%" valign=top align=right><%=FormatNumber(totInterest,2)%></td>
                    <td width="7%" valign=top align=right><%=FormatNumber(totCommission,2)%></td>
                    <td width="5%" valign=top align=right><%=FormatNumber(totSECFee,2)%></td>
                    <td width="4%" valign=top align=right><%=FormatNumber(totSvcFee,2)%></td>
                    <td width="9%" valign=top align=right><%=FormatNumber(totNet,2)%></td>
                </TR>
            </table>
        </td>
    </TR>
<%end if%>

basically i need another condition that says if currep <> newrep or firsttime="t" OR if it's the last record in the ADO Recordset then display this is a subtotal as well.

<%

FirstTime="F"
CurRep = adoRsTrade("calIncludedRep")
adoRsTrade.MoveNext

loop%>

any help is greatly appreciated, thank you in advance, NickG

Upvotes: 3

Views: 10721

Answers (1)

BradBrening
BradBrening

Reputation: 5518

You could check for EOF after you call MoveNext on your recordset to test if you are on the last record.

For example:

Do While adoRsTrade.AbsolutePage = iPageCurrent And Not adoRsTrade.EOF
  ' DO SOME STUFF
  ' --------------
  ' --------------
  adoRsTrade.MoveNext
  If adoRsTrade.EOF Then
    ' last record!
    ' DO SOME OTHER STUFF
  End If
Loop

Upvotes: 8

Related Questions