VB and VBA Users Source Code: Converting the ADOB error collection into a user friendly error message
[
Home
|
Contents
|
Search
|
Reply
| Previous | Next ]
VB/VBA Source Code
Converting the ADOB error collection into a user friendly error message
By:
Andrew Baker
Email (spam proof):
Email the originator of this post
Date:
Thursday, October 23, 2003
Hits:
1152
Category:
Database/SQL/ADO
Article:
The function below retuns an error string from an ADO Connection. 'Purpose : Converts the adodb errors object into a user friendly error message 'Inputs : oConn The connection to return the errors from 'Outputs : Returns an error message or an empty string if no errors where present 'Author : Andrew Baker 'Date : 23/07/2000 19:07 'Notes : This function uses UBound with an error handler and allows you to specify a default return value 'Revisions : Function ConnectionErrorText(oConn As ADODB.Connection) As String Dim lThisError As Long, lPosText As String, sResult As String Dim sThisError As String 'Loop over the errors collection For lThisError = 0 To oConn.errors.count - 1 sThisError = oConn.errors(lThisError) lPosText = InStrRev(sThisError, "]") If lPosText Then 'Remove the MS error text sResult = sResult & mid$(sThisError, lPosText + 1) & vbNewLine Else sResult = sResult & sThisError & vbNewLine End If Next If Right$(sResult, 2) = vbNewLine Then sResult = left(sResult, Len(sResult) - 2) End If 'Return the result ConnectionErrorText = sResult End Function
Terms and Conditions
Support this site
Download a trial version of the Excel Workbook Rebuilder