Good day folks
My access program connected to SQL Server has a table tbl1 has a composite key (col1 and col2). Naturally these two will not take duplicates. I have code that is set to trap duplicate entry errors as below.
I commented out the runtime error number 3146 because that works fine. However this particular error is being thrown by SQL Server and I was hoping that my DAO Error trap should catch that. However it doesnt and I am unable to fully debug this as the save option is not available in design mode.
The idea is that if someone tries to enter a duplicate name in either col1 or col2 SQL server throws an ODBC error 3146 or 3627. Either way this subsequently causes a runtime error in access. I am able to trap the runtime error but not the DAO Error which my code appears to be attempting to trap.
Do you guys have any idea as to what I may be doing wrong?
Update - I also attached a screenshot of the exact error including error codes that we thrown by Access as a runtime error and SQL Server as an ODBC call error for further clarification when the save button is pressed.
Thanks
My access program connected to SQL Server has a table tbl1 has a composite key (col1 and col2). Naturally these two will not take duplicates. I have code that is set to trap duplicate entry errors as below.
Code:
Private Sub cmdsave_Click()
On Error GoTo err_duplicate
'....some code
err_duplicate:
'If Err.Number = 3146 Then
'MsgBox "Error Number" & " " & Err.Number & vbNewLine & " " & "This record contains errors (possible duplicate name/serial)", vbExclamation + vbOKOnly, "Error"
'Else
Dim errN As DAO.Error
If Errors.Count > 1 Then
For Each errN In DAO.Errors
If errN.Number = 3043 Or errN.Number = 3146 Or errN.Number = 3151 Or errN.Number = 11004 Then
MsgBox "Error Number" & errN.Number & vbNewLine & "This name or serial is already being used. Please create a new PC record", vbExclamation + vbOKOnly, "Error"
End If
Next errN
'End If
End If
End Sub
I commented out the runtime error number 3146 because that works fine. However this particular error is being thrown by SQL Server and I was hoping that my DAO Error trap should catch that. However it doesnt and I am unable to fully debug this as the save option is not available in design mode.
The idea is that if someone tries to enter a duplicate name in either col1 or col2 SQL server throws an ODBC error 3146 or 3627. Either way this subsequently causes a runtime error in access. I am able to trap the runtime error but not the DAO Error which my code appears to be attempting to trap.
Do you guys have any idea as to what I may be doing wrong?
Update - I also attached a screenshot of the exact error including error codes that we thrown by Access as a runtime error and SQL Server as an ODBC call error for further clarification when the save button is pressed.
Thanks
Attachments
Last edited: