|
我想捕获数据库中的查询,窗体,报表中报出的错误,然后追加进入报表中,我在别处摘抄了一段代码,但是放到自己的数据库中就报错,请问有没有相类似的代码或范例,谢谢
Sub ErrorLog(error As String, Key1 As String, Key2 As String, Error_Step As Integer, FrmCode As String, LoopNo As Integer, ProcName As String)
'Created by IBI November 1998
On Error GoTo errorLog_Err
MsgBox "Please contact your database administrator " + Chr(10) + Chr(13) + error, vbInformation
SQLText = "INSERT INTO ErrorLog ( [Date], Key1, Key2, [Error Step], FrmCode, LoopNo, ProcName ) SELECT #" & Now() & "# AS [Date], '" + Key1 + "' AS Key1, '" + Key2 + "' AS Key2, " & Error_Step & " AS [Error Step], '" + fName + "' AS FrmCode, " & LoopNo & " AS LoopNo, '" + ProcName + "' AS ProcName;"
DoCmd.RunSQL SQLText
errorLog_Exit:
Exit Sub
errorLog_Err:
MsgBox "Please Contact your Database Administrator " + Chr(10) + Chr(13) + error$
Resume errorLog_Exit
End Sub
将上述代码写入程序代码内
例子
End If
Else
MsgBox "You Have no Access to this process"
End If
Exit_DC:
Exit Sub
Err_DC:
Call ErrorLog(error$, Key1, Key2, Step, fName, LoopNo, ProcName) '此处引用代码
Resume Exit_DC
End Sub
|
|