I have a page that does two queries, the second using a value from the first, looping thru two different tables for different reasons. My problem is that there may not be a record in the second table (which is fine), but my code doesn't want to recognize that there is no recordset. Here is the code:
My code works fine when there is a record in event_pmts, but if there is no matching record, then I get the
'Item cannot be found in the collection corresponding to the requested name or ordinal.'
What am I missing or forgetting? EOF doesn't work, the recordcount always comes back as -1 and I am out of ideas. How can I skip this section of vbscript if the recordset is empty? Any help out there?
wb
Code:
sql2 = "select insert_date, pmt_amount, payor, description as descr from ycmhome.event_pmts where registration_id = " & regid & " ORDER BY registration_id "
sql2 = sql2 & "compute sum(pmt_amount) by registration_id"
set rs2 = conn.Execute(sql2)
<% rs2.MoveFirst %>
<% Do Until rs2.eof %>
<tr>
<td colspan="6">Additional Information:</td></tr>
<tr>
<th class="a">Date</th><th class="a">Name</th><th class="a">Amount</th><th class="a">Description</th><td colspan="2"> </td></tr>
<tr>
<td><%=rs2("insert_Date") %></td><td><%=rs2("payor") %></td><td><%=formatcurrency(rs2("pmt_amount"),2) %></td><td><%=rs2("descr") %></td></tr>
<%rs2.MoveNext
Loop %>
<% set rs2 = rs2.NextRecordSet() %>
<% Dim total_amount : total_amount = rs2(0) %>
<tr>
<td colspan="2">Totals</td><td><%=formatcurrency(total_amount,2) %></td><td colspan="3"> </td></tr>
<% rs2.close
set rs2 = Nothing %>
'Item cannot be found in the collection corresponding to the requested name or ordinal.'
What am I missing or forgetting? EOF doesn't work, the recordcount always comes back as -1 and I am out of ideas. How can I skip this section of vbscript if the recordset is empty? Any help out there?
wb