Reputation: 315
I'm running a bunch of MS-Access querys from a VBA script using DoCmd.RunQuery, some of this querys when runned directly give errors of the kind "MS Access could not add XX registers due to ... " and I would like to get a log of them.
Something like
DoCmd.RunQUery "query 1"
If "There is an Error" Then
Debug.Print "error message"
End If
And I would like to know how I can implement "There is an error" and "error message" parts. Thanks.
Upvotes: 0
Views: 86
Reputation: 6336
You can use something like this:
On Error Resume Next
CurrentDb.Execute "sql query", dbFailOnError
lngErrNum = Err.Number
strErrDescr = Err.Description
On Error GoTo ErrorHandler
If lngErrNum <> 0 Then
Debug.Print strErrDescr
End If
Upvotes: 1