A
Albert S.
Hello,
We need to export a query from Access to a text file using UTF-8 encoding. I
have seen that the export
query wizard has an option to export as UTF-8, but I don't see how to do
this in vba. We need this exact
format because the text file has strict guidelines for use. The query name
is qryMARC and it will contain up
to 18 lines of text for each record. I also saw the object
"System.Text.UTF8", but I'm not sure how to use
that with this output.
Thanks,
Albert
Here is the code:
Private Sub cmdWrite_Click()
Dim FileNumber As Integer
Dim strLine As String
Dim rs As DAO.Recordset
Dim i As Integer
Dim strMakrPath As String
Dim strFullPath As String
Dim strFormatedFile As String
strFormatedFile = "FileName"
FileNumber = FreeFile
strMakrPath = "C:\MARC\marcmakr.exe"
Set rs = CurrentDb.OpenRecordset("qryMARC", dbOpenDynaset, dbSeeChanges)
Open "C:\MARC\TF" & strFormatedFile & ".txt" For Output As #FileNumber
Do While Not rs.EOF
For i = 0 To 18
strLine = "" & Nz(rs.Fields(i))
If Len(strLine) > 0 Then
Print #FileNumber, strLine
End If
Next i
Print #FileNumber,
rs.MoveNext
Loop
strFullPath = strMakrPath & " " & "C:\MARC\TF" & strFormatedFile & ".txt"
& " " & "C:\MARC\TF" &
strFormatedFile & ".mrc" & " " & "C:\MARC\text21.txt"
Shell strFullPath, vbHide
End Sub
We need to export a query from Access to a text file using UTF-8 encoding. I
have seen that the export
query wizard has an option to export as UTF-8, but I don't see how to do
this in vba. We need this exact
format because the text file has strict guidelines for use. The query name
is qryMARC and it will contain up
to 18 lines of text for each record. I also saw the object
"System.Text.UTF8", but I'm not sure how to use
that with this output.
Thanks,
Albert
Here is the code:
Private Sub cmdWrite_Click()
Dim FileNumber As Integer
Dim strLine As String
Dim rs As DAO.Recordset
Dim i As Integer
Dim strMakrPath As String
Dim strFullPath As String
Dim strFormatedFile As String
strFormatedFile = "FileName"
FileNumber = FreeFile
strMakrPath = "C:\MARC\marcmakr.exe"
Set rs = CurrentDb.OpenRecordset("qryMARC", dbOpenDynaset, dbSeeChanges)
Open "C:\MARC\TF" & strFormatedFile & ".txt" For Output As #FileNumber
Do While Not rs.EOF
For i = 0 To 18
strLine = "" & Nz(rs.Fields(i))
If Len(strLine) > 0 Then
Print #FileNumber, strLine
End If
Next i
Print #FileNumber,
rs.MoveNext
Loop
strFullPath = strMakrPath & " " & "C:\MARC\TF" & strFormatedFile & ".txt"
& " " & "C:\MARC\TF" &
strFormatedFile & ".mrc" & " " & "C:\MARC\text21.txt"
Shell strFullPath, vbHide
End Sub