How can I manage error code SQL in MS access form database?

做~自己de王妃 提交于 2019-12-12 06:56:54

问题


I want manage SQL server error code in access form sample duplicate error from SQL server


回答1:


In Access VBA, you need to use:

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



回答2:


You may have to retrieve the Errors collection of the Error object as described here.

It shows this example code:

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 


来源:https://stackoverflow.com/questions/47172000/how-can-i-manage-error-code-sql-in-ms-access-form-database

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!