|
-
Mar 6th, 2002, 08:17 PM
#1
Thread Starter
Hyperactive Member
Entering line by line in a CSV file
Hi all,
I need to export my ado recordset to a CSV File. I have created the CSV file, but all the records are appeaing side by side instead of line by line.
I need my output as
Colname1 Colname2
record 1 xxxxxxx xxxxxx
record 2 xxxxxxx xxxxxx
how do i do that..someone pls help.
Thanks and Regards,
Venkat.
-
Mar 6th, 2002, 08:34 PM
#2
It sounds like you need to put a vbCrLf after the last field of each record. Without seeing your code, its hard to say.
-
Mar 6th, 2002, 08:41 PM
#3
Thread Starter
Hyperactive Member
here is my code;
i used VBcrlf, but it said some error..
-----------------------------------------------
Pls send any code alterations to this email id
[email protected]
thanks.
Dim rsExport As New ADODB.Recordset
Dim objfile As New FileSystemObject
Dim objcsv
Dim strCSVSQL As String
strCSVSQL = "SELECT cola, colb from mytbl
rsExport.Open strCSVSQL, QConn, 1, 2
Set objcsv = objfile.CreateTextFile("c:\ReportCSV.csv")
rsExport.MoveFirst
'Writing the table column names
For i = 0 To (rsExport.Fields.Count - 1)
'objcsv.Write ("""")
objcsv.Write (rsExport.Fields(i).Name)
'objcsv.Write ("""")
If (i <> (rsExport.Fields.Count - 1)) Then
objcsv.Write (",")
End If
Next
'objcsv.writeln()
vbCrLf
Dim k
k = 0
'Writing field values
Do While Not (rsExport.EOF Or rsExport.BOF)
For k = 0 To (rsExport.Fields.Count - 1)
'objcsv.Write ("""")
objcsv.Write (rsExport(k))
'objcsv.Write ("""")
If (k <> (rsExport.Fields.Count - 1)) Then
objcsv.Write (",")
End If
Next
'objcsv.writeln()
vbCrLf
rsExport.MoveNext
Loop
Thanks and Regards,
Venkat.
-
Mar 6th, 2002, 08:54 PM
#4
Try changing this:
'objcsv.writeln()
vbCrLf
rsExport.MoveNext
To this:
'objcsv.writeln()
objcsv.Write (vbCrLf )
rsExport.MoveNext
-
Mar 6th, 2002, 09:36 PM
#5
Thread Starter
Hyperactive Member
great...
thats fantastic..it worked..thank you very much
Thanks and Regards,
Venkat.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|