Voici mon programme mais j'ai une erreur pour la déclaration de rs, l'erreur est ADODB Recordset error
Operation is not allowed when the object is closed
<%
Set NB_Conn = Server.CreateObject("Mysql.Connection")
Set rs=Server.CreateObject("ADODB.RecordSet")
NB_Conn.Connect NB_MySQL_Qualite_host,NB_MySQL_Qualite_user,NB_MySQL_Qualit e_pasw,NB_MySQL_Qualite_database,NB_MySQL_Qualite_port,0
Action = LEFT(UCASE(Request("Action")),5)
If Action = "RECEV" Then ' Arrivée du formulaire
' 1. Mémorisation de l'adresse E-mail dans un cookie
Response.Cookies("sgmail")= Request("Mail")
Response.Cookies("sgmail").Expires = Date+365
Response.Cookies("sgmail").Domain="saint-gobain.com"
Response.Cookies("sgmail").Path = "/images"
' 2. Tri de la Base de Données
SQL = "SELECT Societe.ID_Societe, Societe.Nom_societe FROM Societe " _
& " ORDER BY Societe.Nom_societe DESC "
If not NB_Conn.query(SQL) Then MySQLError(NB_Conn)
set societe = Server.CreateObject("Mysql.Recordset")
societe.Connection = NB_Conn
' 3. Création du fichier
Set FSO = Server.CreateObject("Scripting.FileSystemObject")
dim dir : dir = Server.MapPath("/images")
set inF = FSO.CreateTextFile(dir & "\" & Request("type"))
' Fichier au format Excel (.slk)
if RIGHT(Request("type"),3)="slk" then
inF.writeLine"ID;PWXL;N;E" ' Début du codage excel
' chr (34) remplace les guillements à la suite de l'instruction
inF.writeLine"C;Y1;X1;K"&CHR(34)&("ID_Societe")&CHR(34)
inF.writeLine"C;Y1;X2;K"&CHR(34)&("Nom_societe")&CHR(34)
i=2 ' Affichage à partir de la ligne 2
While Not rs.eof
inF.writeLine"C;Y"&(""&i&";X1;K")&(rs("ID_Societe"))
inF.writeLine"C;Y"&(""&i&";X2;K")&CHR(34)&(rs("Nom_societe" ))&CHR(34)
i=i+1
rs.MoveNext
wend
inF2.writeLine"E" ' Fin du codage excel
' ou fichier au format texte (.txt)
else
inF.writeLine("Id_Societe"&";"&"Nom_societe"&";")
While Not rs.eof
inF.writeLine(rs("Id_Societe")&";"&rs("Nom_societe")&";")
rs.MoveNext
wend
end if
inF.close
' 4. Fermeture de la connexion à la BD
rs.close : set rs = nothing
OBJdbConnection.close : set OBJdbConnection = nothing
' 5. Envoi du fichier par ASPMail
Set Mailer = Server.CreateObject("SMTPsvg.Mailer")
Mailer.FromName = "Defort"
Mailer.FromAddress= "defort.fabien@saint-gobain.com"
Mailer.RemoteHost = "SMTP.saint-gobain.com"
Mailer.AddRecipient Request("Mail"), Request("Mail")
Mailer.AddAttachment dir&"\"&Request("type")
Mailer.Organization = "Site de saint gobain sekurit"
Mailer.Subject = "L'envoi des défauts et des expéditions"
strBody = "Voici la liste des défauts et des expéditions" & VbCrLf
strBody = strBody & "Nom du fichier joint "&Request("type")&"." & VbCrLf
strBody = strBody & "Amicalement. Fabien" & VbCrLf
Mailer.BodyText = strBody
if Mailer.SendMail then
msg="Félicitations : La liste des expéditions et des défauts est dans votre boite aux lettres" _
& "<br>Fichier : "&Request("type")
else
msg="Problème d'envoi<br>"&Mailer.Response
end if
End If %>
<html><head><title>Test pour envoi de fichier vers excel</title>
</head><body bgcolor="#FFFFFF" text="#000000" leftmargin="0" topmargin="0" marginwidth="0" marginheight="0">
<!--#include virtual="/include/haut.html" -->
<%if msg="" then%>
<H2 align="center">Test pour le transfert de données
dans un fichier "Excel" ou "Texte"</H2>
<h2 align="center"> </h2>
<form method="POST" action="excel.asp">
<table border="0" cellspacing="2" width="100%">
<tr align="center">
<td>Recevez ce fichier en indiquant simplement<BR><BR></td>
</tr><tr align="center">
<td><select size="1" name="type">
<option value="excel.slk">excel</option>
<option value="texte.txt">texte</option>
</select> le type de fichier choisi<BR><BR></td>
</tr><tr align="center">
<td><input type="text" name="Mail" size="22"
value="<%=Request.Cookies("sgmail")%>"> votre e-mail<BR><BR></td>
</tr><tr align="center">
<td><input type="submit" value="Recevoir" name="Action">
un seul clic suffit ...<BR><BR></td>
</tr>
<TR align="center"><TD>La version excel (fichier *.slk) est compatible avec Excel<BR><BR></TD></TR>
<TR align="center"><TD>La version texte (fichier *.txt) est compatible avec Word, Works, Word Pad etc....</TD></TR>
</table>
</form>
<%else%>
<br>
<p align="center"><b><%=msg%></b></p>
<%end if%>
</body></html>