evergrean100
Technical User
I can create an Excel spreadsheet output with data from my Access 2003 database but now need to create an Excel output with two spreadsheets in one Excel file.
My attempt below is not working. Please advise if this can be done??
Excel can have multiple spreadsheets but I can only get my ASP to output just one Excel with one spreadsheet. Anyone ever output with two spreadsheets??
My attempt below is not working. Please advise if this can be done??
Code:
<%
dim accessdb, cn, rs, sql, sql2
' Connect to the db with a DSN connection
Set conn = Server.CreateObject("ADODB.Connection")
conn.Open "dsn=actis"
' Create a server recordset object
Set rs = Server.CreateObject("ADODB.Recordset")
sql = "SELECT id, " & _
"[lastname], " & _
"[firstname], " & _
"FROM mytable"
rs.Open sql, conn
sql2 = "SELECT idTwo, " & _
"[lastnameTwo], " & _
"[firstnameTwo], " & _
"FROM mytableTwo"
rs.Open sql2, conn
%>
<%
Response.ContentType = "application/vnd.ms-excel"
Response.AddHeader "Content-Disposition", "attachment;filename=ExcelExport.xls"
%>
<html>
<body>
<table BORDER="1" borderColor="gainsboro" align="center">
<tr>
<td>Claim ID</td>
<td>Last Name</td>
<td>First Name</td>
</tr>
' first spreadsheet
<%
' Move to the first record
rs.movefirst
' Start a loop that will end with the last record
do while not rs.eof
%>
<tr>
<td>
<%= rs("combo_id") %>
</td>
<td>
<%= rs("firstname") %>
</td>
<td>
<%= rs("lastname") %>
</td>
</tr>
<%
' Move to the next record
rs.movenext
' Loop back to the do statement
loop %>
</table>
<table BORDER="1" borderColor="gainsboro" align="center">
<tr>
<td>Claim ID</td>
<td>Last Name</td>
<td>First Name</td>
</tr>
'second spread sheet
<%
' Move to the first record
rs.movefirst
' Start a loop that will end with the last record
do while not rs.eof
%>
<tr>
<td>
<%= rs("combo_idTwo") %>
</td>
<td>
<%= rs("firstnameTwo") %>
</td>
<td>
<%= rs("lastnameTwo") %>
</td>
</tr>
<%
' Move to the next record
rs.movenext
' Loop back to the do statement
loop %>
</table>
</body>
</html>
<%
' Close and set the recordset to nothing
rs.close
set rs=nothing
Excel can have multiple spreadsheets but I can only get my ASP to output just one Excel with one spreadsheet. Anyone ever output with two spreadsheets??