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
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
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