mks123,
Glad you found a solution. My initial concerns were why are you using ADODB? And what exactly were you trying to accomplish in plain, simple English?
I don't think my adjustment to your code, or the solution at the link you provided are necessarily appropriate solutions. But, then again, readers don't know your business issue in any detail.
As for the code you asked about:
Code:
140 With Errloop
150 strTmp = strTmp & vbCrLf & "ADO Error # " & i & ":"
160 strTmp = strTmp & vbCrLf & " ADO Error # " & .number
170 strTmp = strTmp & vbCrLf & " Description " & .Description
180 strTmp = strTmp & vbCrLf & " Source " & .source
190 i = i + 1
200 End With
210 Next
220 Debug.Print strTmp
230 MsgBox strTmp
I don't use ADODB very often. I use DAO almost exclusively.
Anyway, I used google to find
https://support.microsoft.com/en-us/...ordset-objects
Review the ERROR NOTES in the article for specifics.
I recommend that you include Option Explicit in your modules to force Dimming all variables.
ADO Connection object has an errors collection.
Code:
'must DIM variables to be used
Dim errs1 As ADODB.Errors 'this is the Errors Collection
Dim Errloop As ADODB.Error 'this is an individual Error
Dim strTmp As String ' this is to hold the ADODB.Error text
.....
.....
120 Set errs1 = Conn.Errors
'this code loops through each Error in the Errors Collection
'which means there can be 0,1, or many error(s) found for the Connection object
130 For Each Errloop In errs1
140 With Errloop
'this code builds up a message for any/all errors found
150 strTmp = strTmp & vbCrLf & "ADO Error # " & i & ":"
160 strTmp = strTmp & vbCrLf & " ADO Error # " & .number
170 strTmp = strTmp & vbCrLf & " Description " & .Description
180 strTmp = strTmp & vbCrLf & " Source " & .source
190 i = i + 1
200 End With
210 Next
'this line Prints the ADODB message to the immediate window
220 Debug.Print strTmp
'this line outputs the MsgBox to the screen
230 MsgBox strTmp
'this is my error handler from MZTools
240 MsgBox "Error " & err.number & " in line " & Erl & " (" & err.Description & ") in procedure AddRecord of Module ModuleTesting_CanKill"
End Sub
Good luck.