Error Handling Query Errors

bs0d

Well-known Member
Joined
Dec 29, 2006
Messages
622
I'm not real polished on error handling, and I'd like someone to sanity check my function. Here's what is intended:

run 3 queries (insert, delete, insert)
capture rows affected
store error numbers and descriptions (if any)
provide update status in update log table

Code:
Public Function myUpdate()

Dim dbs As DAO.Database
Set dbs = CurrentDb
Dim lngPropertiesAdded As Long
Dim lngRowsAdded As Long
Dim lngRowsDeleted As Long
Dim lngNewRows As Long
Dim ErrLoop As Error
Dim StrErrorNum As String
Dim StrErrorDesc As String

On Error GoTo Error_Handler

'Add properties:
dbs.Execute "__Append_tblProperties", dbFailOnError
lngPropertiesAdded = dbs.RecordsAffected

'Delete previous X:
dbs.Execute "__Delete_Changed_Dates", dbFailOnError
lngRowsDeleted = dbs.RecordsAffected

'Append all daily data:
dbs.Execute "__Append_data", dbFailOnError
lngRowsAdded = dbs.RecordsAffected

lngNewRows = lngRowsAdded - lngRowsDeleted

'Record update:
dbs.Execute "INSERT INTO tblTaskUpdateLog ( runDate, PropertiesAdded, RowsDeleted, RowsAdded, NewRows, Errors, ErrorDescription )" & _
"VALUES (Now(), " & lngPropertiesAdded & ", " & lngRowsDeleted & ", " & lngRowsAdded & ", " & lngNewRows & ", " & StrErrorNum & ", '" & StrErrorDesc & "');", dbFailOnError

Set dbs = Nothing
Application.Quit

Error_Handler:
If DBEngine.Errors.Count > 0 Then
    For Each ErrLoop In DBEngine.Errors
        StrErrorNum = ErrLoop.Number & ", "
        StrErrorDesc = ErrLoop.Description & ", "
    Next ErrLoop
End If
Resume Next
    
End Function

For Access 2013, I assume an error in the query terminates the query execution and no records will be changed, is this correct?
Will Resume Next in the handler attempt each query regardless of possible error of previous? Thanks for any feedback
 

Excel Facts

Fastest way to copy a worksheet?
Hold down the Ctrl key while dragging tab for Sheet1 to the right. Excel will make a copy of the worksheet.

Forum statistics

Threads
1,223,909
Messages
6,175,310
Members
452,634
Latest member
cpostell

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top