Grazie per il prezioso suggerimento.
Prima di confezionare e spedire il msg email sto provando a generare per ciascun soggetto il proprio file excel, ma lo script mi crea quattro file esxcel con i dati sbagliati e solo l'ultimo con i dati corretti, perchè? Cosa sbaglio?
Grazie
codice:
'CONNESSIONE AL DB
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 PER LA CREAZIONE DEL FILE EXCEL
sub listaGuasti(cn, byRef listaGuastiOutput)
SQL = "SELECT * FROM "
SQL = SQL & " tbl_1 "
SQL = SQL & " WHERE "
SQL = SQL & " soggetto = '" & Rs1("soggetto") & "'; "
set rs = server.createObject("ADODB.Recordset")
rs.open SQL, cn
if not rs.eof then
listaGuastiOutput = rs.getrows()
end if
rs.Close()
Set rs = Nothing
end sub
'QUERY SU SOGGETTI ASSOCIATI A 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("SOGGETTO")
Set fs = CreateObject("Scripting.FileSystemObject")
path_modello = server.mappath("/public/modello_excel.txt")
path_temp = server.mappath("/public/" & temp_excel_file & ".xls")
Set a = fs.OpenTextFile(path_modello)
file_letto = a.readall
a.Close
call listaGuasti(cn, listaGuastiOutput)
tabella_guasti = ""
guasti_totale = 0
if IsArray(listaGuastiOutput) then
guasti_totale = Ubound(listaGuastiOutput,2)
For risultato = 0 to guasti_totale
tabella_guasti = tabella_guasti & "<tr style=vertical-align:middle;>"
tabella_guasti = tabella_guasti & "<td class=xl6430278Bordi style=text-align:center;>" & listaGuastiOutput(0,risultato) & "</td>"
tabella_guasti = tabella_guasti & "<td class=xl6430278Bordi style=text-align:center;>" & listaGuastiOutput(1,risultato) & "</td>"
tabella_guasti = tabella_guasti & "<td class=xl6430278Bordi style=text-align:center;>" & listaGuastiOutput(2,risultato) & "</td>"
tabella_guasti = tabella_guasti & "<td class=xl6430278Bordi style=text-align:center;>" & listaGuastiOutput(3,risultato) & "</td>"
tabella_guasti = tabella_guasti & "<td class=xl6430278Bordi style=text-align:center;>" & listaGuastiOutput(4,risultato) & "</td>"
tabella_guasti = tabella_guasti & "<td class=xl6430278Bordi style=text-align:center;>" & listaGuastiOutput(5,risultato) & "</td>"
tabella_guasti = tabella_guasti & "<td class=xl6430278Bordi style=text-align:center;>" & listaGuastiOutput(6,risultato) & "</td>"
tabella_guasti = tabella_guasti & "<td class=xl6430278Bordi style=text-align:center;>" & listaGuastiOutput(7,risultato) & "</td>"
tabella_guasti = tabella_guasti & "<td class=xl6430278Bordi style=text-align:center;>" & listaGuastiOutput(8,risultato) & "</td>"
tabella_guasti = tabella_guasti & "<td class=xl6430278Bordi style=text-align:center;>" & listaGuastiOutput(9,risultato) & "</td>"
tabella_guasti = tabella_guasti & "<td class=xl6430278Bordi style=text-align:center;>" & listaGuastiOutput(10,risultato) & "</td>"
tabella_guasti = tabella_guasti & "<td class=xl6430278Bordi style=text-align:center;>" & listaGuastiOutput(11,risultato) & "</td>"
tabella_guasti = tabella_guasti & "<td class=xl6430278Bordi style=text-align:center;>" & listaGuastiOutput(12,risultato) & "</td>"
tabella_guasti = tabella_guasti & "<td class=xl6430278Bordi style=text-align:center;>" & listaGuastiOutput(13,risultato) & "</td>"
tabella_guasti = tabella_guasti & "<td class=xl6430278Bordi style=text-align:center;>" & listaGuastiOutput(14,risultato) & "</td>"
tabella_guasti = tabella_guasti & "<td class=xl6430278Bordi style=text-align:center;>" & listaGuastiOutput(15,risultato) & "</td>"
tabella_guasti = tabella_guasti & "<td class=xl6430278Bordi style=text-align:center;>" & listaGuastiOutput(16,risultato) & "</td>"
tabella_guasti = tabella_guasti & "<td class=xl6430278Bordi style=text-align:center;>" & listaGuastiOutput(17,risultato) & "</td>"
tabella_guasti = tabella_guasti & "<td class=xl6430278Bordi style=text-align:center;>" & formatNumber(listaGuastiOutput(18,risultato),0) & "</td>"
tabella_guasti = tabella_guasti & "<td class=xl6430278Bordi style=text-align:center;>" & formatNumber(listaGuastiOutput(19,risultato),0) & "</td>"
tabella_guasti = tabella_guasti & "</tr>"
Next
end if
Set a = fs.CreateTextFile(path_temp, True)
file_letto = replace(file_letto, "[guasti_totale]", guasti_totale+1)
file_letto = replace(file_letto, "[guasti]", tabella_guasti)
a.write (file_letto)
a.Close
set fs = nothing
Rs1.MoveNext()
Loop
End if
Rs1.Close()
Set Rs1 = Nothing
cn.Close()
Set cn = Nothing
%>