如何在MS访问表单数据库中管理错误代码SQL?

时间:2017-11-08 05:10:13

标签: sql sql-server ms-access duplicates

我想在访问表单中管理SQL服务器错误代码 来自SQL Server的样本重复错误

enter image description here

2 个答案:

答案 0 :(得分:0)

在Access VBA中,您需要使用:

On Error GoTo Error_Handler
' YOUR CODE HERE
.
.
.
Return_Label:
Exit Function

Error_Handler:
'What goes here depends on the data access model
Resume Return_Label

答案 1 :(得分:0)

您可能必须按照here所述检索错误对象的错误集合。

它显示了此示例代码:

Sub DescriptionX() 

   Dim dbsTest As Database 

   On Error GoTo ErrorHandler 

   ' Intentionally trigger an error. 
   Set dbsTest = OpenDatabase("NoDatabase") 

   Exit Sub 

ErrorHandler: 
   Dim strError As String 
   Dim errLoop As Error 

   ' Enumerate Errors collection and display properties of  
   ' each Error object. 
   For Each errLoop In Errors 
      With errLoop 
         strError = _ 
            "Error #" & .Number & vbCr 
         strError = strError & _ 
            "  " & .Description & vbCr 
         strError = strError & _ 
            "  (Source: " & .Source & ")" & vbCr 
         strError = strError & _ 
            "Press F1 to see topic " & .HelpContext & vbCr 
         strError = strError & _ 
            "  in the file " & .HelpFile & "." 
      End With 
      MsgBox strError 
   Next 

   Resume Next 

End Sub