T
td
I am using the code below which was lifted from the Code Librarian in Access
2000. Unfortunately the code generates an error "Type Mismatch" when the file
does not exist in the line:
Set f = fso.CreateTextFile(gSettings.LogFile, False)
(gSettings.LogFile is a user defined variable with .LogFile defined as
string and appears to contain a legitmate path as a string)
Could you please explain why there is a mismatch?
TIA
td
================================
Public Function WriteLogFile(Msg as string) as boolean
Dim fso As FileSystemObject
Dim f As File
Dim txtStream As TextStream
Set fso = New FileSystemObject
On Error Resume Next
' See if file already exists.
Set f = fso.GetFile(gSettings.LogFile)
' If not, then create it.
If Err <> 0 Then
Set f = fso.CreateTextFile(gSettings.LogFile, False)
If Err Then
'Could not create the file
WriteLogFile = False
Exit Function
End If
End If
On Error GoTo 0
' Open file as text stream for reading.
Set txtStream = f.OpenAsTextStream(ForAppending)
' Write error information and close.
With txtStream
.WriteLine Format(Date, "Short Date") & Msg
.Close
End With
End Function
2000. Unfortunately the code generates an error "Type Mismatch" when the file
does not exist in the line:
Set f = fso.CreateTextFile(gSettings.LogFile, False)
(gSettings.LogFile is a user defined variable with .LogFile defined as
string and appears to contain a legitmate path as a string)
Could you please explain why there is a mismatch?
TIA
td
================================
Public Function WriteLogFile(Msg as string) as boolean
Dim fso As FileSystemObject
Dim f As File
Dim txtStream As TextStream
Set fso = New FileSystemObject
On Error Resume Next
' See if file already exists.
Set f = fso.GetFile(gSettings.LogFile)
' If not, then create it.
If Err <> 0 Then
Set f = fso.CreateTextFile(gSettings.LogFile, False)
If Err Then
'Could not create the file
WriteLogFile = False
Exit Function
End If
End If
On Error GoTo 0
' Open file as text stream for reading.
Set txtStream = f.OpenAsTextStream(ForAppending)
' Write error information and close.
With txtStream
.WriteLine Format(Date, "Short Date") & Msg
.Close
End With
End Function