T
Thomas M
Word 2000
I have the following subroutine. A couple of the variables in the Write
command are set in another routine that calls this one. Those variables
are declared at the module level.
******************
Option Base 1
Option Explicit
Sub ErrorLogging()
Dim ErrDateTime As Date
Dim ErrorLog As String
Dim ErrorLogName As String
Dim vbErrLogPath As String
Dim FileNumber As Long
Dim FSO As Object
On Error GoTo ErrorHandler
FileNumber = FreeFile
Set FSO = CreateObject("Scripting.FileSystemObject")
ErrorLogName = "Error.log"
vbErrLogPath = ActiveDocument.Variables.Item("ErrorLogPath").Value & "\"
ErrorLog = vbErrLogPath & ErrorLogName
ErrDateTime = FormatDateTime(Now, vbGeneralDate)
On Error Resume Next
If IsError(FSO.getFile(ErrorLog)) Then
Open ErrorLog For Output As FileNumber
Else
Open ErrorLog For Append As FileNumber
End If
On Error GoTo ErrorHandler
Write #FileNumber, ErrDateTime, ModuleName, Subroutine, Err.Number,
Err.Context, Err.Description, Err.HelpFile, cbDataClip
Write #FileNumber,
Close #FileNumber
Exit Sub
ErrorHandler:
If Err.Number = 53 Or Err.Number = 5825 Then
Dialogs(wdDialogFileOpen).Display
ActiveDocument.Variables("ErrorLogPath").Value = CurDir
End If
Resume
End Sub
******************
Before I test this code I make sure that the ErrorLogPath document
variable does NOT exist. This produces an error with the vbErrLogPath =
command, which causes execution to move to ErrorHandler. ErrorHandler
should allow the user to specify the path to the error log when
Err.Number = 53 (File not found) or 5825 (Application-defined or object-
defined error--i.e. Document variable doesn't exist). Instead, the IF
statement in ErrorHandler causes the following error:
Run-time error '91':
Object variable or With block variable not set
This code was working earlier tonight, and I'm not sure what I did to
break it. I've tried to isolate the problem by changing the way that the
routine handles errors, but each time there is a reference to the Err
object, I get Run-time error 91.
So the problem seems to be related to the Err object. But at the same
time, that doesn't seem to make any sense because Err is an intrinsic
object and does not need to be declared.
I'm stumped. Can someone tell me why I'm getting Run-time error 91?
--Tom
I have the following subroutine. A couple of the variables in the Write
command are set in another routine that calls this one. Those variables
are declared at the module level.
******************
Option Base 1
Option Explicit
Sub ErrorLogging()
Dim ErrDateTime As Date
Dim ErrorLog As String
Dim ErrorLogName As String
Dim vbErrLogPath As String
Dim FileNumber As Long
Dim FSO As Object
On Error GoTo ErrorHandler
FileNumber = FreeFile
Set FSO = CreateObject("Scripting.FileSystemObject")
ErrorLogName = "Error.log"
vbErrLogPath = ActiveDocument.Variables.Item("ErrorLogPath").Value & "\"
ErrorLog = vbErrLogPath & ErrorLogName
ErrDateTime = FormatDateTime(Now, vbGeneralDate)
On Error Resume Next
If IsError(FSO.getFile(ErrorLog)) Then
Open ErrorLog For Output As FileNumber
Else
Open ErrorLog For Append As FileNumber
End If
On Error GoTo ErrorHandler
Write #FileNumber, ErrDateTime, ModuleName, Subroutine, Err.Number,
Err.Context, Err.Description, Err.HelpFile, cbDataClip
Write #FileNumber,
Close #FileNumber
Exit Sub
ErrorHandler:
If Err.Number = 53 Or Err.Number = 5825 Then
Dialogs(wdDialogFileOpen).Display
ActiveDocument.Variables("ErrorLogPath").Value = CurDir
End If
Resume
End Sub
******************
Before I test this code I make sure that the ErrorLogPath document
variable does NOT exist. This produces an error with the vbErrLogPath =
command, which causes execution to move to ErrorHandler. ErrorHandler
should allow the user to specify the path to the error log when
Err.Number = 53 (File not found) or 5825 (Application-defined or object-
defined error--i.e. Document variable doesn't exist). Instead, the IF
statement in ErrorHandler causes the following error:
Run-time error '91':
Object variable or With block variable not set
This code was working earlier tonight, and I'm not sure what I did to
break it. I've tried to isolate the problem by changing the way that the
routine handles errors, but each time there is a reference to the Err
object, I get Run-time error 91.
So the problem seems to be related to the Err object. But at the same
time, that doesn't seem to make any sense because Err is an intrinsic
object and does not need to be declared.
I'm stumped. Can someone tell me why I'm getting Run-time error 91?
--Tom