Hello I am working in MS Access VBA I am writing code to loop through all query defs and append them to a text file. When the query sql contains utf-8 characters, my output file contains "???" where the UTF-8 characters should appear. I would like the utf-8 characters appear in the text file. My Code is below, any help would be appreciated.
Sub PrintQueries()
Dim strSeparator As String
Dim strFileName As String
Dim returnvalue As Variant
Dim qdef As QueryDef
Dim qdefs As QueryDefs
Dim strQueryName As String
Dim strQuery As String
Dim strdate As String
strdate = Replace(Replace(Now(), "/", "-"), ":", ".")
Set qdefs = Application.CodeDb.QueryDefs
strFileName = "C:\temp\Queries_" & strdate & ".txt"
For Each qdef In qdefs
strQueryName = qdef.Name
If Left(strQueryName, 1) <> "~" Then
Call TxtAppend(strFileName, strQueryName)
strQuery = qdef.SQL '<-- What if strQuery contains utf-8?
Call TxtAppend(strFileName, strQuery) '<-- Call function
strSeparator = "===================="
Call TxtAppend(strFileName, strSeparator)
End If
Next
returnvalue = Shell("notepad.exe" & strFileName, vbNormalFocus)
End Sub
Public Function TxtAppend(strFileName As String, strText As String)
Dim intFileNumber As Integer
intFileNumber = FreeFile
Open strFileName For Append As #intFileNumber
Print #intFileNumber, strText
Close #intFileNumber
End Function