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))

'HERE NEED TO MOVE result OBJECT TO CSV FILE
   

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

Open in new window

maverick0728Asked:
Who is Participating?
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 ChongCommented:
ok, so what object is cGetRecordset returned? is it a ADODB.Recordset object?
0
maverick0728Author Commented:
correct, a ADODB.Recordset object
0
Rory ArchibaldCommented:
You can use GetString:

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

Do Until result.EOF

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

Loop

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

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

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.