Excel VBA transfer recordset to csv file

I have a recordset object that I want to transfer to a .csv file.
Here is the code I have that is returning data to the "result" object.  I need to take the "result" object and save it to a UNC path csv file.
Private Sub cmdMoveToERP_Click()
  On Error GoTo ErrHandler
  If OnNetwork = True Then
    Dim data As New clsADOwrapper
    Dim strSQL As String
    Dim result As Object

   strSQL = "SELECT QuoteNum, QuoteLine, AssemblySeq, PartNum, IndentedPartNum, Description, RevisionNum, QtyPer, IUM, Parent, PriorPeer, NextPeer, Child, BomSequence, "
   strSQL = strSQL & "BomLevel , RequiredQty FROM dbo.EstAsmTemp "
   strSQL = strSQL & "WHERE QuoteNum = '" & Sheets("Initialization").Range("B2").Value & "' "
   strSQL = strSQL & "AND QuoteLine = '" & Sheets("Initialization").Range("H2").Value & "' "
   Set result = data.cGetRecordset(CONN_STR, strSQL)
   'MsgBox (CInt(result.RecordCount))


    MsgBox "Not Connected to Network"
    Exit Sub
  End If
  Set data = Nothing
  Exit Sub
End Sub

Open in new window

Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Ryan ChongBusiness Systems Analyst , ex-Senior Application EngineerCommented:
ok, so what object is cGetRecordset returned? is it a ADODB.Recordset object?
maverick0728Author Commented:
correct, a ADODB.Recordset object
Rory ArchibaldCommented:
You can use GetString:

Open "c:\somefile.csv" For Output As #1

Do Until result.EOF

    Print #1, result.GetString(, 200, ",", vbCrLf, "")


Close #1

Open in new window

Large recordsets can lead to slow performance with GetString so this code does it in chunks - currently set to 200 rows but you can experiment.

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
maverick0728Author Commented:
works.  thanks.
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft Excel

From novice to tech pro — start learning today.