Wrox Home  
Search P2P Archive for: Go

  Return to Index  

asp_databases thread: Need to send query results to a delimited text file


Message #1 by cody@g... on Fri, 24 Jan 2003 18:58:48
The script below queries the database for names and addresses meeting the 
desired criteria, and writes the results nicely on a web page.  I need to 
write the same results into a delimited text file to be downloaded from 
the site.  Then clients can use either Corel WordPerfect or MSWord to 
generate mailing labels in any desired configuration from the delimited 
text file.

I've been looking at the CreateTextFile method of the FileSystemObject 
Object, but I don't see how to use this with query results.

Any help is much apreciated. Thank you, J.C. Couch

<%
  Dim strBranch
  strBranch = Request.form("BranchSelect")
  sql = "Select 
status,CepLname,CepFname,CepMname,MAddress,MCity,MState,MZipcode FROM 
CepData WHERE branch LIKE '" & strBranch & "' ORDER BY CepLname ASC;"
  Set rsCepData = Server.CreateObject("ADODB.Recordset")
  rsCepData.Open sql, objConn, adOpenForwardOnly, adLockOptimistic, 
adCmdText

 If Not rsCepData.EOF Then                    ' there are listings
  Response.Write "<blockquote>"
  Do While Not rsCepData.EOF
  If rsCepData("status")= "ANS" OR rsCepData("status")= "ASW" OR rsCepData
("status")= "AE" OR rsCepData("status")= "AES" Then
    Response.Write _ 
       " <p><font size=3 face=arial>" & rsCepData("CepLname") & ", " & 
rsCepData("CepFname") & ", " & rsCepData("CepMname") & "<br>" _
		& rsCepData("MAddress") & "<br>" _
		& rsCepData("MCity") & ", " & rsCepData("MState") & " "& 
rsCepData("MZipcode") & "<br>"		
	End If
      rsCepData.MoveNext
    Loop
    Response.Write "</blockquote>"
 
  
   Else                                          ' no listings
    Response.Write "<CENTER><H3>No Records Found</H3></CENTER>"
  End If
  rsCepData.close
%>
Message #2 by cody@g... on Sun, 26 Jan 2003 20:49:21
I found the solution in the TextStream Object

This writes the delimited text file I need for creating the mailing labels 
from those records meeting the specified criterea, but note the record set 
object 'rsCepData' is created previous to(so not included in) this code:

strFilePath = "D:\Inetpub\wwwroot\RVCOG-SS\labels\ceplabelsmfd.txt"
		Set fso = CreateObject("Scripting.FileSystemObject")
		Set strFilePathTS = fso.OpenTextFile(strFilePath, 
ForWriting)
		
		Do While Not rsCepData.EOF
		If rsCepData("status")= "ANS" OR rsCepData("status")
= "ASW" OR rsCepData("status")= "AE" OR rsCepData("status")= "AES" Then
		strFilePathTS.WriteLine rsCepData("CepLname") & ", " & 
rsCepData("CepFname") & ", " & rsCepData("CepMname") & ", " & rsCepData
("MAddress") & ", " & rsCepData("MCity") & ", " & rsCepData("MState") 
& ", " & rsCepData("MZipcode") & ", "
		End If
    		rsCepData.MoveNext
    	Loop
   		strFilePathTS.Close
		
	   Response.Write "<a href=labels/ceplabelsmfd.txt>Download Mail 
Label File</a>"

---------------------------------------------------------------------------

> The script below queries the database for names and addresses meeting 
the 
d> esired criteria, and writes the results nicely on a web page.  I need 
to 
w> rite the same results into a delimited text file to be downloaded from 
t> he site.  Then clients can use either Corel WordPerfect or MSWord to 
g> enerate mailing labels in any desired configuration from the delimited 
t> ext file.

> I've been looking at the CreateTextFile method of the FileSystemObject 
O> bject, but I don't see how to use this with query results.

> Any help is much apreciated. Thank you, J.C. Couch

> <%
 >  Dim strBranch
 >  strBranch = Request.form("BranchSelect")
 >  sql = "Select 
s> tatus,CepLname,CepFname,CepMname,MAddress,MCity,MState,MZipcode FROM 
C> epData WHERE branch LIKE '" & strBranch & "' ORDER BY CepLname ASC;"
 >  Set rsCepData = Server.CreateObject("ADODB.Recordset")
 >  rsCepData.Open sql, objConn, adOpenForwardOnly, adLockOptimistic, 
a> dCmdText

>  If Not rsCepData.EOF Then                    ' there are listings
 >  Response.Write "<blockquote>"
 >  Do While Not rsCepData.EOF
 >  If rsCepData("status")= "ANS" OR rsCepData("status")= "ASW" OR 
rsCepData
(> "status")= "AE" OR rsCepData("status")= "AES" Then
 >    Response.Write _ 
 >       " <p><font size=3 face=arial>" & rsCepData("CepLname") & ", " & 
r> sCepData("CepFname") & ", " & rsCepData("CepMname") & "<br>" _
	> 	& rsCepData("MAddress") & "<br>" _
	> 	& rsCepData("MCity") & ", " & rsCepData("MState") & " "& 
r> sCepData("MZipcode") & "<br>"		
	> End If
 >      rsCepData.MoveNext
 >    Loop
 >    Response.Write "</blockquote>"
 > 
 >  
 >   Else                                          ' no listings
 >    Response.Write "<CENTER><H3>No Records Found</H3></CENTER>"
 >  End If
 >  rsCepData.close
%

  Return to Index