【发布时间】:2015-08-04 17:56:17
【问题描述】:
在 Access 2007 中,我的错误捕获设置为 Break on Unhandled Errors
我希望代码在发生错误的行停止并退出函数,而不是恢复到下一行代码。但是,它似乎对我不起作用。我故意在第 6 行创建了一个错误,以查看它是否会在此行之后退出函数,但它只提示错误处理程序消息,并在发生错误后继续恢复到下一行。 这是我的代码:
GoToBackend():
'Go to current linked backend database
Private Function GoToBackend()
On Error GoTo BackendErrorHandler
'To update BEPath requires two sets of proc.
'Delete Exisiting
RunQuery "DeleteBEEPath" 'Here is where I created error by miss spelling it
'Insert Into
RunQuery "InsertBEPath"
'Prompt alert
MsgBox "Front end tables succesfully linked. Access now needs to run the backend database to complete the linking process. Please ensure macros/vba are enabled if prompted.", 48
Hyperlink.GoHyperlink (Hyperlink.PrepHyperlink(GetBackendPath))
ExitFunction:
Exit Function 'Why won't this exit the function?
BackendErrorHandler:
Dim Msg As String
Msg = Err.Number & ": " & Err.Description
MsgBox Msg
Resume ExitFunction
End Function
RunQuery():
'Run a given query name
Private Function RunQuery(qName As String)
On Error GoTo RunQueryErrorHandler
DoCmd.SetWarnings False
DoCmd.OpenQuery qName
DoCmd.SetWarnings True
ExitFunction:
Exit Function
RunQueryErrorHandler:
Dim Msg As String
Msg = Err.Number & ": " & Err.Description
MsgBox Msg
Resume ExitFunction
End Function
【问题讨论】:
标签: ms-access error-handling vba ms-access-2007