JMongi
Active member
- Local time
- Yesterday, 23:58
- Joined
- Jan 6, 2021
- Messages
- 802
I've checked the VBA MSoft files and can't figure out why this doesn't work. It's probably something basic...
It errors on Set LogFile = fspenTextFile(Log, 8, False, -2)
I didn't explicitly test it, but the other Set LogFile used to create the file seemed to work as the log didn't originally exist before testing and now it does.
Code:
Public Sub WriteErrorLog()
'Code uses enumeration due to late binding
Dim Log As String, LogPath As String
Dim fso As Object, LogFile As Object
Log = "ErrorLog.txt"
LogPath = "C:\KingslyOp\"
If FileExists(LogPath & Log) = False Then
Set fso = CreateObject("Scripting.FileSystemObject")
Set LogFile = fso.CreateTextFile(LogPath & Log, True)
Else
Set LogFile = fso.OpenTextFile(Log, 8, False, -2)
'ForAppending = 8, TristateUseDefault = -2
End If
With LogFile
.WriteBlankLines 1
.Write "Test write"
'.Write "Error " & Err.Number & " in " & ProcName & ": " & Err.Description
.Close
End With
End Sub
It errors on Set LogFile = fspenTextFile(Log, 8, False, -2)
I didn't explicitly test it, but the other Set LogFile used to create the file seemed to work as the log didn't originally exist before testing and now it does.