<% Sub Write_HTML Dim r, count'r is an index variable for the for loops, count is the number of rows of data Dim arrTotals(50) count = rsData.Fields.Count - 1 ' r = "0" for r = 0 to count arrTotals(r) = "0" next rsData.MoveFirst 'recordsets start at zero 'first generate the start of the table Response.Write("<table width='100%' border='1' cellpadding='4'>" & vbCrLf) Response.Write("<THEAD>" & vbCrLf) for r = 0 to count 'populate the header Response.Write("<TH>" & rsData(r).Name & " </TH>" & vbCrLf) Next Response.Write("</THEAD>" & vbCrLf) 'Now populate the table Do Until rsData.EOF Response.Write("<tr>" & vbCrLf) Response.Write("<td>" & rsData(0) & "</td>" & vbCrLf) for r = 1 to count Response.Write("<td>" & rsData(r) & "</td>" & vbCrLf) arrTotals(r) = arrTotals(r) + rsData(r) Next Response.Write("</tr>" & vbCrLf) rsData.MoveNext Loop Response.Write("<tr>" & vbCrLf) Response.Write("<td><b>Totals</b></td>") for r = 1 to count Response.write("<td><b>" & arrTotals(r) & "</b></td>" & vbCrLf ) Next Response.Write("</tr>" & vbCrLf) Response.Write("</table>") End Sub %>