Office中国论坛/Access中国论坛
标题:
如何捕获查询,窗体,报表中的错误
[打印本页]
作者:
yanwei82123300
时间:
2012-1-14 12:27
标题:
如何捕获查询,窗体,报表中的错误
我想捕获数据库中的查询,窗体,报表中报出的错误,然后追加进入报表中,我在别处摘抄了一段代码,但是放到自己的数据库中就报错,请问有没有相类似的代码或范例,谢谢
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
作者:
风中漫步
时间:
2012-1-14 13:22
是个集中错误处理过程吧,第一个参数该是错误描述,后面的....
你想要取得哪些错误信息,就自己改动一下,
作者:
Grant
时间:
2012-1-14 23:08
取消一下错误处理,然后看提示反馈什么错误信息再进行修改
作者:
yanwei82123300
时间:
2012-1-15 09:50
请看系统提示的错误!
欢迎光临 Office中国论坛/Access中国论坛 (http://www.office-cn.net/)
Powered by Discuz! X3.3