Exporting to CSV (1 Viewer)

chrisguk

Registered User.
Local time
Yesterday, 20:21
Joined
Mar 9, 2011
Messages
148
HI,

I am looking for a solution to export to CSV. I have tried many examples around google but cant seem to get them to work My query has more than 65,000 lines.

Can anyone help?

This is the code that I am using:

Code:
DoCmd.TransferText acExportDelim, , "CombinedBills", strFile
 

chrisguk

Registered User.
Local time
Yesterday, 20:21
Joined
Mar 9, 2011
Messages
148
HI,

I am looking for a solution to export to CSV. I have tried many examples around google but cant seem to get them to work My query has more than 65,000 lines.

Can anyone help?

This is the code that I am using:

Code:
DoCmd.TransferText acExportDelim, , "CombinedBills", strFile

I found this solution, but what if I wanted to choose the file location dynamically?

Code:
Dim trz As Integer
Dim strCSV As String
    
    For trz = 1 To 511
        Close #trz
    Next trz
    trz = FreeFile
    Open "c:\Export.csv" For Output Access Write As #trz
    
    With CurrentDb.OpenRecordset("ExportTable", 4)
        Dim x As Integer
            For x = 0 To .Fields.Count - 1
                strCSV = strCSV & strColumnDelimiter & .Fields(x).Name & ", "
            Next x
            Print #trz, Mid(strCSV, Len(strColumnDelimiter) + 1)

        Do Until .EOF
            strCSV = ""
            For x = 0 To .Fields.Count - 1
                strCSV = strCSV & strColumnDelimiter & Nz(.Fields(x), "<NULL>") & ", "
            Next x
            Print #trz, Mid(strCSV, Len(strColumnDelimiter) + 1)
            .MoveNext
        Loop
        
    End With
           
   
    Close #trz
 

Users who are viewing this thread

Top Bottom