Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Access VBA exporting CSV file as UTF-8

I have to export data from Access multiple times a day as a CSV file. The person who had my job before me created this VBA code that exports the data in the click of a button. However, I need to modify it so that it exports as UTF-8 without BOM so that international characters will show up in the software that I import it to.

I can manually export as Text and then save it as CSV, when I go to the "Advanced..." settings I select Code Page: Unicode (UTF-8) and this works perfectly. But as I said before, I want to change the VBA code:

Private Sub Command6_Click()
Dim sExportPath As String
Dim qry As DAO.QueryDef


With Me.List0
    For i = 0 To .ListCount - 1
        If .Selected(i) Then
            sExportPath = Application.CurrentProject.Path & "\final_" & Left(Me.List0.Column(0, i), InStr(Me.List0.Column(0, i), " ") - 1) & ".csv"
            If QueryExists("Final") Then CurrentDb.QueryDefs.Delete "Final"


            Set qry = CurrentDb.CreateQueryDef("Final", "Select Salutation,Email from " & Left(Me.List0.Column(0, i), InStr(Me.List0.Column(0, i), " ") - 1))
            CurrentDb.QueryDefs.Refresh
            DoCmd.TransferText acExportDelim, , "Final", sExportPath, True

        End If
    Next i
End With
End Sub
like image 574
p0tato Avatar asked Sep 02 '25 17:09

p0tato


1 Answers

Use the value 65001 as CodePage parameter (the last one of the TransferText method), which is represents Unicode (UTF-8).

like image 147
CAdeBiasio67 Avatar answered Sep 04 '25 08:09

CAdeBiasio67