hi there, hope in your help.

I have this script for generate one excel file with ASP Classic.

I need generate one different excel file for single Subject in tbl_email.

My problem is with this code are actually created excel files for single Subject in tbl_email, but only the last excel file is correct, the other excel files take only the first row of the table tbl_dates.

Can you help me?
thank you for help
Code:
'CONNECT TO DB MYSQL
Set cn = Server.CreateObject("ADODB.Connection")
cn.Open "DRIVER={MySQL ODBC 5.1 Driver};SERVER=localhost;PORT=3306;DATABASE=XXX;USER=XXX;PASSWORD=XXX;OPTION=3;" 

'SUB FOR CREATION FILE EXCEL
sub myList(cn, byRef myListOutput)    
	SQL = "SELECT * FROM "
	SQL = SQL & " tbl_dates "
	SQL = SQL & " WHERE "
	SQL = SQL & " Subject = '" & Rs1("Subject") & "'; "
        
	set rs = server.createObject("ADODB.Recordset")
	rs.open SQL, cn
		
	if not rs.eof then
		myListOutput = rs.getrows()
        end if  
    
   rs.Close()
   Set rs = Nothing   
end sub	

   'QUERY TO TABLE EMAIL 
    strSQL = "SELECT * FROM tbl_email WHERE email <> '';"
    Set Rs1 = CreateObject("ADODB.Recordset")
    Rs1.Open strSQL, cn

    if not Rs1.eof then 
    Do While Not Rs1.EOF     

    temp_excel_file = Session.SessionID & "_" & Rs1("Subject")

    Set fs = CreateObject("Scripting.FileSystemObject")
    path_template = server.mappath("/public/template_excel.txt")
    path_temp = server.mappath("/public/" & temp_excel_file & ".xls")
    Set a = fs.OpenTextFile(path_template)
    file_read = a.readall
    a.Close

    call myList(cn, myListOutput)

    myTable = ""
    g_total = 0

if IsArray(myListOutput) then
	g_total = Ubound(myListOutput,2)	
	
	For result = 0 to g_total
		myTable = myTable & "<tr style=vertical-align:middle;>"
		
			myTable = myTable & "<td class=xl6430278 style=text-align:center;>" & myListOutput(0,result) & "</td>"
			myTable = myTable & "<td class=xl6430278 style=text-align:center;>" & myListOutput(1,result) & "</td>"
			myTable = myTable & "<td class=xl6430278 style=text-align:center;>" & myListOutput(2,result) & "</td>"
			myTable = myTable & "<td class=xl6430278 style=text-align:center;>" & myListOutput(3,result) & "</td>"
			myTable = myTable & "<td class=xl6430278 style=text-align:center;>" & myListOutput(4,result) & "</td>"
			myTable = myTable & "<td class=xl6430278 style=text-align:center;>" & myListOutput(5,result) & "</td>"
			myTable = myTable & "<td class=xl6430278 style=text-align:center;>" & myListOutput(6,result) & "</td>"
			myTable = myTable & "<td class=xl6430278 style=text-align:center;>" & myListOutput(7,result) & "</td>"
			myTable = myTable & "<td class=xl6430278 style=text-align:center;>" & myListOutput(8,result) & "</td>"
			myTable = myTable & "<td class=xl6430278 style=text-align:center;>" & myListOutput(9,result) & "</td>"
			myTable = myTable & "<td class=xl6430278 style=text-align:center;>" & myListOutput(10,result) & "</td>"
			myTable = myTable & "<td class=xl6430278 style=text-align:center;>" & myListOutput(11,result) & "</td>"
			myTable = myTable & "<td class=xl6430278 style=text-align:center;>" & myListOutput(12,result) & "</td>"
			myTable = myTable & "<td class=xl6430278 style=text-align:center;>" & myListOutput(13,result) & "</td>"
			myTable = myTable & "<td class=xl6430278 style=text-align:center;>" & myListOutput(14,result) & "</td>"
			myTable = myTable & "<td class=xl6430278 style=text-align:center;>" & myListOutput(15,result) & "</td>"
			myTable = myTable & "<td class=xl6430278 style=text-align:center;>" & myListOutput(16,result) & "</td>"
			myTable = myTable & "<td class=xl6430278 style=text-align:center;>" & myListOutput(17,result) & "</td>"
			myTable = myTable & "<td class=xl6430278 style=text-align:center;>" & formatNumber(myListOutput(18,result),0) & "</td>"
			myTable = myTable & "<td class=xl6430278 style=text-align:center;>" & formatNumber(myListOutput(19,result),0) & "</td>"
		
		myTable = myTable & "</tr>"
	Next
	
end if

		Set a = fs.CreateTextFile(path_temp, True)
		file_read = replace(file_read, "[g_total]", g_total+1)
		file_read = replace(file_read, "[g]", myTable)
		a.write (file_read)
		a.Close
		set fs = nothing

		Rs1.MoveNext()
      Loop
      End if
      
   Rs1.Close()
   Set Rs1 = Nothing       

cn.Close()
Set cn = Nothing

%>