Hi Guys,
Please help. I am trying to export data from an Access Database, to a csv file.
I found this item below, and it works for me 99%.
[code=asp]
<object runat="server" progid="Scripti ng.FileSystemOb ject"
id="oFSO"></object>
<%
Dim oADO, oRS
Dim sOutput
Dim aZIPs, i, sZIP
Const OUTPUT_PATH = "D:\Path\"
sSQL = "SELECT DISTINCT(ZIP) FROM Customers"
Set oADO = Server.CreateOb ject("ADODB.Con nection")
oADO.Open YourConnectionS tring
Set oRS = oADO.Execute(sS QL)
aZIPs = oRS.GetRows()
oRS.Close : Set oRS = Nothing
For i = 0 To UBound(aZIPs, 2)
sZIP = aZIPs(0, i)
sSQL = "SELECT CustID,Firstnam e,Lastname,Addr ess,City,State, ZIP FROM
Customers WHERE ZIP='" & sZIP & "'"
Set oRS = oADO.Execute(sS QL)
sOutput = oRS.GetString(, ,",",vbCrLf)
oRS.Close : Set oRS = Nothing
oFSO.CreateText File(OUTPUT_PAT H & sZIP & ".csv", True).Write sOutput
Response.Write "<a href=""" & sZIP & ".csv"">Cli ck here to download CSV
for ZIP code " & sZIP & "</a><br>"
Next
oADO.Close : Set oADO = Nothing
%>[/code]
When I run this, every record in the database is exported.
But, I need the ability to specify which record is exported, preferably with a URL being sent from the previous page (ie mypage.asp?orde r=123456)
The order is unique to each record.
I think it must be something to do with the for next loop.
If I just remove this, only the first record from the database is 'produced', and I am really stuck!
Any help would be great.
Thank you.
Cookie
Please help. I am trying to export data from an Access Database, to a csv file.
I found this item below, and it works for me 99%.
[code=asp]
<object runat="server" progid="Scripti ng.FileSystemOb ject"
id="oFSO"></object>
<%
Dim oADO, oRS
Dim sOutput
Dim aZIPs, i, sZIP
Const OUTPUT_PATH = "D:\Path\"
sSQL = "SELECT DISTINCT(ZIP) FROM Customers"
Set oADO = Server.CreateOb ject("ADODB.Con nection")
oADO.Open YourConnectionS tring
Set oRS = oADO.Execute(sS QL)
aZIPs = oRS.GetRows()
oRS.Close : Set oRS = Nothing
For i = 0 To UBound(aZIPs, 2)
sZIP = aZIPs(0, i)
sSQL = "SELECT CustID,Firstnam e,Lastname,Addr ess,City,State, ZIP FROM
Customers WHERE ZIP='" & sZIP & "'"
Set oRS = oADO.Execute(sS QL)
sOutput = oRS.GetString(, ,",",vbCrLf)
oRS.Close : Set oRS = Nothing
oFSO.CreateText File(OUTPUT_PAT H & sZIP & ".csv", True).Write sOutput
Response.Write "<a href=""" & sZIP & ".csv"">Cli ck here to download CSV
for ZIP code " & sZIP & "</a><br>"
Next
oADO.Close : Set oADO = Nothing
%>[/code]
When I run this, every record in the database is exported.
But, I need the ability to specify which record is exported, preferably with a URL being sent from the previous page (ie mypage.asp?orde r=123456)
The order is unique to each record.
I think it must be something to do with the for next loop.
If I just remove this, only the first record from the database is 'produced', and I am really stuck!
Any help would be great.
Thank you.
Cookie
Comment