<%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
Response.write"<br>Generate CSV Done.<br><a href="&sFileName&">Download</a>"
End If
objRec.Close()
Conn.Close()
Set objRec = Nothing
Set Conn = Nothing
%>
</table>
</body>
</html>