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
使用值65001作为CodePage参数(TransferText方法的最后一个参数),它表示Unicode(UTF-8)。
Perform the export manually and choose "Advanced..." as you did before. After you have chosen the "Code Page" and other settings, click the "Save As..." button to save the export specification. Then you can supply the name of the saved specification as the second argument to the TransferText
method, eg,
DoCmd.TransferText acExportDelim, "MyExportSpecification", "Final", sExportPath, True
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.