Jumat, 23 September 2011

[MS_AccessPros] How to Clear DBEngine.Errors?

 

Hi All,

I have looked for almost two days now and have been unable to find a way to clear DBEngine Errors. I mostly use the code to get more information about ODBC errors working with SQL Azure since ADODB is not supported. The documentation says the DBEngine Errors are read only. So even though there are no current DBEngine Errors my error code shows the last DBEngine Error every time my error code runs.

So I have to resort to using the workaround hack I wrote below unless someone has a better idea.

Is there an API that will clear the DBEngine.Errors or some other way to handle this issue?

'This Sub raises an error and calls a function to check for DBEngine Errors
Sub ErrorTest()
On Error GoTo ErrHandle

Dim lngTest As Long

lngTest = 1 / 0

ExitHere:
Exit Sub

ErrHandle:
MsgBox PAWErrors & "In Procedure ErrorTest.", vbCritical
Resume ExitHere

End Sub

Function PAWErrors() As String

Dim dbErr As DAO.Database
Dim i As Long
Dim strErr As String
Dim strDBErr As String

If Err.Number > 0 Then
strErr = "Error Number: " & Err.Number & " " & Err.Description & vbCr
End If

With DBEngine
For i = 0 To .Errors.Count - 1
If .Errors(i).Description <> "Could not find file 'NoDB'." Then
strDBErr = strDBErr & "DBEngine Error Number " _
& .Errors(i).Number & " " & .Errors(i).Description & vbCr
End If
Next i
End With

If Len(strDBErr & vbNullstring) > 0 Then
On Error Resume Next
'Trigger a DBEngine error to use as a flag.
Set dbErr = OpenDatabase("NoDB")
End If

PAWErrors = strErr & strDBErr

End Function

Kind Regards,
Patrick Wood
Access Easy Tips Blog
http://accesstips.wordpress.com
Microsoft Access and SQL Azure Information Center for Developers
http://gainingaccess.net/SQLAzure/AccessAndSQLAzureInfo.aspx

__._,_.___
Recent Activity:
MARKETPLACE

Stay on top of your group activity without leaving the page you're on - Get the Yahoo! Toolbar now.

.

__,_._,___

Tidak ada komentar:

Posting Komentar