Hi:
I have a recordset that I need to export to excel. It is telling me that my recordset is empty. Can someone glance over my code and tell me where I am wrong. Thanks
<HTML>
<HEAD>
<TITLE>Create Tab Delimited Text File</TITLE>
</HEAD>
<body>
<%
OpenADOConn
Dim strSQL
Dim rs
set rs = server.CreateObject("ADODB.Recordset"
strSQL= "mysqlstatement(itslong)"
rs.Open strSQL,ADOConn,1,2
%>
<Script language=vbscript>
'Create a randome Filename
nRandom = Int((1000000 - 1 + 1) * Rnd + 1000000)
fileExcel = "t" & CStr(nRandom) & ".xls"
filename= "U:\My Documents\test\new.xls"
'Create the File with extension .xls using the FileSytemObject
'If the file does not exist, the TRUE parameter will allow it
'to be created. Make sure the user* impersonated has write
'permissions to the directory where the file is being created.
Set fs = CreateObject("Scripting.FileSystemObject"
set MyFile=fs.CreateTextFile(filename,true)
'Open the connection and retrieve data from the database
strLine="" 'Initialize the variable for storing the filednames
For each x in rs.fields
'Separate field names with tab so that these appear in
'different columns in Excel
strLine= strLine & x.name & chr(9)
Next
'Write this string into the file
MyFile.writeline strLine
'Response.Write MyFile
'Retrieve the values from the database and write into the database
Do while Not rs.EOF
strLine=""
for each x in rs.Fields
strLine= strLine & x.value & chr(9)
Response.Write strLine
next
MyFile.writeline strLine
rs.MoveNext
Loop
'Clean up
MyFile.Close
Set MyFile=Nothing
Set fs=Nothing
'Show a link to the Excel File.
link="<A HREF=" & fileExcel & ">Open Excel</a>"
Response.write link
rs.Close
Set rs = Nothing
CloseADOConn
</Script>
</BODY>
</HTML>
Thank You
I have a recordset that I need to export to excel. It is telling me that my recordset is empty. Can someone glance over my code and tell me where I am wrong. Thanks
<HTML>
<HEAD>
<TITLE>Create Tab Delimited Text File</TITLE>
</HEAD>
<body>
<%
OpenADOConn
Dim strSQL
Dim rs
set rs = server.CreateObject("ADODB.Recordset"
strSQL= "mysqlstatement(itslong)"
rs.Open strSQL,ADOConn,1,2
%>
<Script language=vbscript>
'Create a randome Filename
nRandom = Int((1000000 - 1 + 1) * Rnd + 1000000)
fileExcel = "t" & CStr(nRandom) & ".xls"
filename= "U:\My Documents\test\new.xls"
'Create the File with extension .xls using the FileSytemObject
'If the file does not exist, the TRUE parameter will allow it
'to be created. Make sure the user* impersonated has write
'permissions to the directory where the file is being created.
Set fs = CreateObject("Scripting.FileSystemObject"
set MyFile=fs.CreateTextFile(filename,true)
'Open the connection and retrieve data from the database
strLine="" 'Initialize the variable for storing the filednames
For each x in rs.fields
'Separate field names with tab so that these appear in
'different columns in Excel
strLine= strLine & x.name & chr(9)
Next
'Write this string into the file
MyFile.writeline strLine
'Response.Write MyFile
'Retrieve the values from the database and write into the database
Do while Not rs.EOF
strLine=""
for each x in rs.Fields
strLine= strLine & x.value & chr(9)
Response.Write strLine
next
MyFile.writeline strLine
rs.MoveNext
Loop
'Clean up
MyFile.Close
Set MyFile=Nothing
Set fs=Nothing
'Show a link to the Excel File.
link="<A HREF=" & fileExcel & ">Open Excel</a>"
Response.write link
rs.Close
Set rs = Nothing
CloseADOConn
</Script>
</BODY>
</HTML>
Thank You