<%Option Explicit%>
<html>
<head>
<title>ThaiCreate.Com ASP & Export Access To CSV</title>
</head>
<body>
<%
Dim objFSO,oFiles
Dim Conn,strSQL,objRec
Dim sFileName
'*** Connect to Access ***'
Set Conn = Server.Createobject("ADODB.Connection")
Conn.Open "DRIVER=Microsoft Access Driver (*.mdb);DBQ=" & Server.MapPath("mydatabase.mdb"),"" , ""
strSQL = "SELECT * FROM customer "
Set objRec = Server.CreateObject("ADODB.Recordset")
objRec.Open strSQL, Conn, 1,3
If Not objRec.EOF Then
sFileName = "customer.csv"
'*** Create Object ***'
Set objFSO = CreateObject("Scripting.FileSystemObject")
'*** Create Text Files ***'
Set oFiles = objFSO.CreateTextFile(Server.MapPath(sFileName), 2)
While Not objRec.EOF
oFiles.WriteLine(objRec.Fields("CustomerID").Value&","&_
objRec.Fields("Name").Value&","&_
objRec.Fields("Email").Value&","&objRec.Fields("CountryCode").Value&","&_
objRec.Fields("Budget").Value&","&objRec.Fields("Used").Value)
objRec.MoveNext()
Wend
oFiles.Close()
Set oFiles = Nothing
Set objFSO = Nothing
'**************** Send Email ******************'
Dim myMail,HTML,strMsg
Set myMail = Server.CreateObject("CDONTS.NewMail")
If Trim(sFileName) <> "" Then
myMail.AttachFile Server.MapPath(sFileName)
End If
myMail.From = "Webmaster <[email protected]>"
myMail.Value("Reply-To") = "[email protected]"
myMail.To = "[email protected]"
myMail.Subject = "My CSV"
myMail.MailFormat = 0
myMail.BodyFormat = 0
myMail.Body = "Convert Access to CSV"
myMail.Send
Set myMail = Nothing
'*************** End Send Email ***************'
Response.write"Generate CSV and Email Sending."
End If
objRec.Close()
Conn.Close()
Set objRec = Nothing
Set Conn = Nothing
%>
</table>
</body>
</html>