'Run the queries
On Error Resume Next
j = 0
For i = LBound(aQ, 1) To UBound(aQ, 1)
'Check if the query is to be run
If aQ(i, 7) = True Then
[COLOR=Blue] 'Reset error trapping
lECount = 0
lEAdjust = 0
sQueryErrors = ""
bMoveNext = False[/COLOR]
'Write run order
j = j + 1
sRunOrder = j & " of " & lQCount
'Get the query SQL
sSQL = ""
sSQL = GetQuerySQL(CStr(aQ(i, 1)))
'Check if getting query SQL was successful
If Err Then
'Record failure and error message, clear error
aQ(i, 3) = False
aQ(i, 4) = "[GetSQL] Error " & Err.Number & ": " & Err.Description
Err.Clear
Else
Do
'Run the query and time it
t_bef = Timer
db.Execute sSQL, dbFailOnError
lRCount = db.RecordsAffected
t_aft = Timer
[COLOR=blue] 'Check if running query SQL was successful
If Err Then
'Add error info to string
sQueryErrors = _
sQueryErrors & _
Now & vbTab & "[" & Err.Number & "]" & vbTab & Err.Description & _
vbNewLine
'Count how many times we have encountered an error
lECount = lECount + 1
If lECount >= clUserCanceledThreshold + lEAdjust Then
'Something has likely gone wrong (e.g. not accidentally cancelled)
Select Case MsgBox( _
"During operation " & sRunOrder & " """ & CStr(aQ(i, 1)) & _
""", the following " & lECount & " error(s) was/were triggered:" & _
String(2, vbNewLine) & _
sQueryErrors, _
vbAbortRetryIgnore + vbExclamation)
Case vbAbort
bAbort = True
bMoveNext = True
Case vbRetry
lEAdjust = lEAdjust + clUserCanceledThreshold
bMoveNext = False
Case vbIgnore
bMoveNext = True
End Select
End If
If bMoveNext = True Then
'Record latest failure and error message
aQ(i, 3) = False
aQ(i, 4) = "[Execute] Error " & Err.Number & ": " & Err.Description
End If
'Clear error
Err.Clear
Else
'Record success
aQ(i, 3) = True
bMoveNext = True
End If
Loop Until bMoveNext = True[/COLOR]
End If
'Save the runtime
aQ(i, 2) = t_aft - t_bef
t_tot = t_tot + aQ(i, 2)
t_bef = 0
t_aft = 0
'Keep track of total successes
lSCount = lSCount + aQ(i, 3)
'Save the log data to the refresh log detail table
RefreshLogDetail_InsertNewRecord _
RefreshID:=lRefreshID, _
RunningOrder:=sRunOrder, _
QueryName:=CStr(aQ(i, 1)), _
DurationInSeconds:=CSng(aQ(i, 2)), _
WasSuccessful:=CBool(aQ(i, 3)), _
ErrorDescription:=CStr(aQ(i, 4))
'If there is a table updated, record the
' update time in zhtblTableUpdates
If aQ(i, 5) <> "" And aQ(i, 3) = True Then
InsertTableImportDate _
ImportedTableName:=CStr(aQ(i, 5)), _
RecordsAffected:=lRCount, _
ManualDate:=dTimeStamp
End If
'Add to the finish message
sMsgTimer = FormatTimer( _
StartTimer:=0, _
EndTimer:=CSng(aQ(i, 2)), _
OutputFormat:=fMinsAndSecsShort)
sMsgFull = _
sMsgFull & vbNewLine & _
j & ". " & CStr(aQ(i, 1)) & " = " & sMsgTimer & IIf(aQ(i, 3), "", " (Fail)")
If bAbort Then Exit For
End If
Next i
On Error GoTo -1
On Error GoTo 0