将数据写入文本文件写入中文

时间:2016-10-29 00:45:39

标签: vba ms-access access-vba ms-access-2013 fso

我正在尝试将数据从VBA写入文本文件。我的语法显示没有调试或编译错误,但是当方法完成并且我打开文本文件时,它没有任何可读性。这一切似乎都是中文的。这是我的语法,是什么让输出关闭以使其难以辨认?

Function WriteData(fulllocale As String, tblName As String, CString As String)
  Dim fso As Object
  Set fso = CreateObject("Scripting.FileSystemObject")

  Dim Fileout As Object
  'Set Fileout = fso.OpenTextFile("C:\Test.txt", ForAppending, True)
  Set Fileout = fso.OpenTextFile("C:\Test.txt", 8, True)
  Fileout.Write fulllocale & "," & tblName & "," & CString & vbCrLf
  Fileout.Close
End Function

编辑 - 附加信息
这些是传递的值(不是作为描述的粗体文本)
数据库名称: C:\ Test \ db1.accdb
表名:日志
连接信息: ODBC; DRIVER = SQL Server; SERVER = servername; UID = userid; PWD =密码; APP = Microsoft Office 2013; DATABASE = database



编辑2
这是我用来调用

的语法
Sub Testing()
Dim Fileout As Object
Dim fso As Object
Dim objFSO As Object
Dim accapp As Access.Application
Dim db As DAO.Database
Dim tdf As DAO.TableDef
Dim colFiles As Collection
Set objFSO = CreateObject("Scripting.FileSystemObject")

Dim objRegExp As Object
Set objRegExp = CreateObject("VBScript.RegExp")
objRegExp.pattern = ".accdb"
objRegExp.IgnoreCase = True

Set colFiles = New Collection

RecursiveFileSearch "C:\Databases\", objRegExp, colFiles, objFSO

For Each f In colFiles
    Set accapp = New Access.Application
    accapp.OpenCurrentDatabase (f)
    On Error Resume Next
    accapp.Visible = False
    Set db = accapp.CurrentDb
    For Each tdf In db.TableDefs
      If Not (tdf.Name Like "MSys*") Then
        WriteData CStr(f), tdf.Name, tdf.Connect
      End If
    Next
    Set tdf = Nothing
    Set db = Nothing
Next
Set objFSO = Nothing
Set objRegExp = Nothing

End Sub

0 个答案:

没有答案