Hey,
Does anybody know of a way in Access 97 to trap an error thrown by a macro. The macro is been called in vba by docmd.runmacro so I presumed that the error thrown by the macro would be caught by VBA error handling but it is not.
Any ideas?
Ps. I know this is easier in the newest versions of access but unfortunately on 97 is available.
Does anybody know of a way in Access 97 to trap an error thrown by a macro. The macro is been called in vba by docmd.runmacro so I presumed that the error thrown by the macro would be caught by VBA error handling but it is not.
Any ideas?
Ps. I know this is easier in the newest versions of access but unfortunately on 97 is available.
Code:
Public Function RunMacro(ByVal strMacName As String, Optional ByVal strLogFile As String = "") As Boolean
'Runs a maco and writes whether the macro completed or not to a log file
'strMacName: The name of the macro to run
'strLogFile: Name of a specific log file to write to. If this is left out the standad log file is used.... <current dir>\Access Macro Logs\<Database Name>\<macro name>\<current date & time(yyyymmdd_hhnn)>.txt
On Error GoTo RunMacro_End
Dim strTimeStamp As String
strTimeStamp = Format(now(), "yyyymmdd_hhnn")
If Len(strLogFile) = 0 Then
CreateStandardLogFile strMacName, strTimeStamp, strLogFile
End If
DoCmd.RunMacro strMacName
RunMacro_End:
If Err.Number <> 0 Then
RunMacro = False
WriteLineToText strLogFile, strTimeStamp & ": ***ERROR***: " & Err.Description
Else
RunMacro = True
WriteLineToText strLogFile, strTimeStamp & ": Completed Normally"
End If
End Function