Results 1 to 5 of 5

Thread: Entering line by line in a CSV file

  1. #1

    Thread Starter
    Hyperactive Member venkatraman_r's Avatar
    Join Date
    Jul 1999
    Location
    Chennai, INDIA
    Posts
    284

    Lightbulb 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.

  2. #2
    PowerPoster jdc2000's Avatar
    Join Date
    Oct 2001
    Location
    Idaho Falls, Idaho USA
    Posts
    2,526
    It sounds like you need to put a vbCrLf after the last field of each record. Without seeing your code, its hard to say.

  3. #3

    Thread Starter
    Hyperactive Member venkatraman_r's Avatar
    Join Date
    Jul 1999
    Location
    Chennai, INDIA
    Posts
    284
    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.

  4. #4
    PowerPoster jdc2000's Avatar
    Join Date
    Oct 2001
    Location
    Idaho Falls, Idaho USA
    Posts
    2,526
    Try changing this:

    'objcsv.writeln()
    vbCrLf
    rsExport.MoveNext


    To this:

    'objcsv.writeln()
    objcsv.Write (vbCrLf )
    rsExport.MoveNext

  5. #5

    Thread Starter
    Hyperactive Member venkatraman_r's Avatar
    Join Date
    Jul 1999
    Location
    Chennai, INDIA
    Posts
    284

    Smile 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
  •  



Click Here to Expand Forum to Full Width