M
Montana DOJ Help Desk
Word 2000
I have the following routine that I'm developing. Please note that there
are bugs in this code, as I have not yet finished and tested it, but those
bugs shouldn't matter much for this particular question. For example, the
If IsError statement is not going to work as written because the On Error
GoTo ErrorHandler statement. But let's just ignore that little detail and
happily assume that all is well on that count. For now, I just want to
concentrate on what happens in ErrorHandler.
***************
Sub ErrorLogging()
Dim dlgAnswer As String
Dim ErrorLog As String
Dim FileNumber As Long
Dim FSO As Object
On Error GoTo ErrorHandler
FileNumber = FreeFile
Set FSO = CreateObject("Scripting.FileSystemObject")
ErrorLog = "Z:\Share\HelpDesk\Locates\Error.log"
If IsError(FSO.getFile(ErrorLog)) Then
Open ErrorLog For Output As FileNumber
Else
Open ErrorLog For Append As FileNumber
End If
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 Then
dlgAnswer = Dialogs(wdDialogFileSaveAs).Show
ActiveDocument.Variables("ErrorLogPath").Value = dlgAnswer
End If
Resume
End Sub
***************
The path stored in ErrorLog will cause an error because there is no Z: drive
on my machine (This is done deliberately for testing purposes). The error
will cause code execution to jump down to ErrorHandler. My goal with
ErrorHandler is to let the user specify the path for the error log, and then
to save that path as a document variable (Eventually, this document variable
will be used to set the value of ErrorLog). The code in ErrorHandler works
splendidly for this purpose--IF the file happens to be the active document.
However, in this routine, the error log is NOT the active document, so the
code in ErrorHandler doesn't do the job.
How can I allow the user to specify the path to the error log, and then
capture the path value that is returned?
-- Tom
State of Montana
Department of Justice Help Desk
"Making the world a safer place."
I have the following routine that I'm developing. Please note that there
are bugs in this code, as I have not yet finished and tested it, but those
bugs shouldn't matter much for this particular question. For example, the
If IsError statement is not going to work as written because the On Error
GoTo ErrorHandler statement. But let's just ignore that little detail and
happily assume that all is well on that count. For now, I just want to
concentrate on what happens in ErrorHandler.
***************
Sub ErrorLogging()
Dim dlgAnswer As String
Dim ErrorLog As String
Dim FileNumber As Long
Dim FSO As Object
On Error GoTo ErrorHandler
FileNumber = FreeFile
Set FSO = CreateObject("Scripting.FileSystemObject")
ErrorLog = "Z:\Share\HelpDesk\Locates\Error.log"
If IsError(FSO.getFile(ErrorLog)) Then
Open ErrorLog For Output As FileNumber
Else
Open ErrorLog For Append As FileNumber
End If
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 Then
dlgAnswer = Dialogs(wdDialogFileSaveAs).Show
ActiveDocument.Variables("ErrorLogPath").Value = dlgAnswer
End If
Resume
End Sub
***************
The path stored in ErrorLog will cause an error because there is no Z: drive
on my machine (This is done deliberately for testing purposes). The error
will cause code execution to jump down to ErrorHandler. My goal with
ErrorHandler is to let the user specify the path for the error log, and then
to save that path as a document variable (Eventually, this document variable
will be used to set the value of ErrorLog). The code in ErrorHandler works
splendidly for this purpose--IF the file happens to be the active document.
However, in this routine, the error log is NOT the active document, so the
code in ErrorHandler doesn't do the job.
How can I allow the user to specify the path to the error log, and then
capture the path value that is returned?
-- Tom
State of Montana
Department of Justice Help Desk
"Making the world a safer place."