export string to csv file

Posted on 2011-04-18
Last Modified: 2012-05-11
I have a string I would like to export to a csv file but am not sure what I am doing wrong. I think it may be in the DoCmd.TransferText.

Any ideas?
Dim rs

Set qd = CurrentDb.QueryDefs("qryInvoice_1ToExportToAccountingInsert")
For cnt = 0 To qd.Parameters.Count - 1
   qd.Parameters(cnt) = Eval(qd.Parameters(cnt).Name)
Next cnt

Set rs = qd.OpenRecordset()

Do While Not rs.EOF

'Amount including tax
sSql = "411000," & rs!ClientCodeID & ",0," & rs!TotalIncludingTax & "," & rs!InvoiceDate & _
",VT," & rs!InvoiceCompanyName & "," & rs!InvoiceNumber & vbCrLf

'Amount excluding tax
sSql = sSql & "706100,," & rs!TotalExcludingTax & ",0," & rs!InvoiceDate & _
",VT," & rs!InvoiceCompanyName & "," & rs!InvoiceNumber & vbCrLf

If rs!TotalTax <> 0 Then
sSql = sSql & "445713000,," & rs!TotalTax & ",0," & rs!InvoiceDate & _
",VT," & rs!InvoiceCompanyName & "," & rs!InvoiceNumber & vbCrLf
End If

'rs("DateExportedToAccounting") = date
        'go to next recotd
    Set rs = Nothing

DoCmd.TransferText acExportDelim, "", sSql, "H:\import\results.csv", False, ""

Open in new window

Question by:Shawn
    LVL 1

    Accepted Solution

    found answer at utter access. one of the first times it actually beat ee.

    Dim hFile As Integer
    Dim strFilename As String

    strFilename = "YourPathAndFilename.csv"

    hFile = FreeFile

    Open strFilename For Output As #hFile

    Print #hFile, strYourTextContent

    Close #hFile

    LVL 1

    Author Closing Comment

    solution found

    Featured Post

    IT, Stop Being Called Into Every Meeting

    Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

    Join & Write a Comment

    Most if not all databases provide tools to filter data; even simple mail-merge programs might offer basic filtering capabilities. This is so important that, although Access has many built-in features to help the user in this task, developers often n…
    In a multiple monitor setup, if you don't want to use AutoCenter to position your popup forms, you have a problem: where will they appear?  Sometimes you may have an additional problem: where the devil did they go?  If you last had a popup form open…
    Familiarize people with the process of utilizing SQL Server stored procedures from within Microsoft Access. Microsoft Access is a very powerful client/server development tool. One of the SQL Server objects that you can interact with from within Micr…
    What’s inside an Access Desktop Database. Will look at the basic interface, Navigation Pane (Database Container), Tables, Queries, Forms, Report, Macro’s, and VBA code.

    729 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    20 Experts available now in Live!

    Get 1:1 Help Now