Article ID: 167957
Article Last Modified on 3/2/2005
Private Sub cmdTemplate_Click()
Dim Conn1 As Connection
Dim Errs1 As Errors
Dim i As Integer
Dim StrTmp
On Error GoTo AdoError
Set Conn1 = CreateObject("ADODB.Connection")
' Open connection to Bogus ODBC Data Source for BIBLIO.MDB
Conn1.ConnectionString = "DBQ=BIBLIO.MDB;" & _
"DRIVER={Microsoft Access Driver (*.mdb)};" & _
"DefaultDir=C:\Bogus\Directory\Path;" & _
"UID=admin;PWD=;"
Conn1.Open
' Remaining code goes here.
Done:
' Close all open objects.
If Conn1.State = adStateOpen Then
Conn1.Close
End If
' Destroy anything not destroyed yet.
Set Conn1 = Nothing
' We're done.
Exit Sub
AdoError:
Dim errLoop As Error
Dim strError As String
i = 1
' Process
StrTmp = StrTmp & vbCrLf & "VB Error # " & Str(Err.Number)
StrTmp = StrTmp & vbCrLf & " Generated by " & Err.Source
StrTmp = StrTmp & vbCrLf & " Description " & Err.Description
' Enumerate Errors collection and display properties of
' each Error object.
Set Errs1 = Conn1.Errors
For Each errLoop In Errs1
With errLoop
StrTmp = StrTmp & vbCrLf & "Error #" & i & ":"
StrTmp = StrTmp & vbCrLf & " ADO Error #" & .Number
StrTmp = StrTmp & vbCrLf & " Description " & .Description
StrTmp = StrTmp & vbCrLf & " Source " & .Source
i = i + 1
End With
Next
MsgBox StrTmp
' Clean up Gracefully
On Error Resume Next
GoTo Done
End Sub
168335 INFO: Using ActiveX Data Objects (ADO) via Visual Basic
168354 INFO: Underlying OLE and OLEDB Provider Errors Are Exposed Through ADO
Keywords: kberrmsg kbinfo KB167957