I'm trying to create a sub that writes to a log file. If the file exists, append to it, otherwise create it:
The CreateTextFile code works fine. But the OpenTextFile writes out the text in Chinese. What am I doing wrong here?Code:Option Compare Database Const ForReading = 1, ForWriting = 2, ForAppending = 8 Function LogMessage(message As String) Dim logFileName As String Dim fso As Object Set fso = CreateObject("Scripting.FileSystemObject") Dim file As Object logFileName = CurrentProject.Path & "\MyLog.txt" Dim filePath As String filePath = "" filePath = Dir(logFileName) If filePath = "" Then Set file = fso.CreateTextFile(logFileName, True, True) Else Set file = fso.OpenTextFile(logFileName, ForAppending) End If file.WriteLine Now & ": " & message file.Close Set fso = Nothing Set file = Nothing End Function
Thanks




Reply With Quote
