Err_Proc:
Select Case Err.Number
Case 9
'' display a message if you want
Resume Next '''' assuming you want to just pick up at the statement after the error
Case Else
s = "Insert into API_Errors(ErrorMessage,TableName, [TableID],FileName, ValuesSent) Values ('" & Err.Number & "--" & Err.Description & "','" & sTable & "'," & Nz(pk, "") & ",'" & sFile & "','') "
CurrentDb.Execute s
' MsgBox Err.Number & "--" & Err.Description, vbOKOnly
' Resume ExitImportDataToCaspio
Resume Next
End Select
You could use the Sleep API call...
...followed by a Resume, to attempt to run the same line of code againI have been using already API sleep function in my code, and therefore my main question was how to ensure it tries to execute again (after sleeping) the same line of code which caused the error, taking in consideration that it can come from different locations in my function.
s = "Insert into API_Errors(ErrorMessage,TableName, [TableID],FileName, ValuesSent) Values ('" & Err.Number & "--" & Err.Description & "','" & sTable & "'," & Nz(pk, "") & ",'" & sFile & "','') "
CurrentDb.Execute s
<!DOCTYPE HTML PUBLIC ~-//W3C//DTD HTML 4.01//EN~~http://www.w3.org/TR/html4/strict.dtd~>
<HTML><HEAD><TITLE>Service Unavailable</TITLE>
<META HTTP-EQUIV=~Content-Type~ Content=~text/html; charset=us-ascii~></HEAD>
<BODY><h2>Service Unavailable</h2>
<hr><p>HTTP Error 503. The service is unavailable.</p>
</BODY></HTML>
Dim variable As New ClassType
Cause it behaves differently than in OO languages like C# or VB or VB.NET. It will auto-create an instance on each variable access when the reference is Nothing:Option Compare Database
Option Explicit
Public Sub TestDimAsNew()
Dim variable As New clsTestClass
Set variable = New clsTestClass
variable.Test = "txtMyTextBox"
Debug.Print "1"; variable.Test
Set variable = Nothing
Debug.Print "2"; variable.Test
End Sub
withOption Compare Database
Option Explicit
Private m_Test As String
Public Property Get Test() As String
Test = m_Test
End Property
Public Property Let Test(AValue As String)
m_Test = AValue
End Property
This means that you cannot longer test for uninitalized instances. And when using COM+ objects, this means that when these error out and get Nothing, you wouldn't catch that. Thus it should be really avoided in most cases.
objHTTP.Send JsonConverter.ConvertToJson(patient)
If objHTTP.ResponseText <> "" Then
If InStr(1, objHTTP.ResponseText, " in field 'PatientID' is invalid because it does not exist in the related parent table 'Patients' (field 'PatientID')") > 0 Then
Call AddPatient(columns(iPatIDCol), access_token)
objHTTP.Send JsonConverter.ConvertToJson(patient)
Else
s = "Insert into API_Errors(ErrorMessage,TableName, [TableID],FileName, ValuesSent) Values ('" & Replace(Replace(objHTTP.ResponseText, """", "~"), "'", "") & "','" & sTable & "'," & pk & ",'" & sFile & "','" & JsonConverter.ConvertToJson(patient) & "') "
CurrentDb.Execute s
If InStr(1, objHTTP.ResponseText, "HTTP Error 503") > 0 Then
Sleep 1000
Resume
End If
End If
'Debug.Print objHTTP.ResponseText
Else
Option Compare Database
Option Explicit
Private Enum EnumApiCallStatus
acsNoError,
acsRetryNecessary,
acsRetryFailed,
acsRetrySucceded
' And maybe some more.
End Enum
Private Function ApiCallImpl(AParameters As Variant, ByRef OStatus As EnumApiCallStatus) As Boolean
On Local Error GoTo LocalError
' The actual API call..
' Here you log the verbose/debug informations of your API calls.
ApiCallImpl = True ' Call was successful.
OStatus = acsNoError
Exit Function
LocalError:
ApiCallImpl = (Err.Number <> 503)
If ApiCallImpl Then
' Here are only real exceptions/errors logged.
' These will not be propagated.
Resume Next
' Or you set a different status here.
Else
OStatus = acsRetryNecessary
End If
End Function
Private Function ApiCallIntf(Parameters As Variant, ByRef OStatus As EnumApiCallStatus) As Boolean
' No logging needed here.
ApiCallIntf = ApiCallImpl(Parameters, OStatus)
If OStatus = acsRetryNecessary Then
' Sleep or an other way of scheduling it.
Sleep 60000
ApiCallIntf = ApiCallImpl(Parameters, OStatus)
If OStatus = acsNoError Then
OStatus = acsRetrySucceded
Else
OStatus = acsRetryFailed
End If
End If
End Function
This is just a quick outline. Then your actual business logic looks readable:Private Function AddPatientIntf(patient)
Dim Status As EnumApiCallStatus
If ApiCallIntf(patient, Status) Then 'JSON handling is down in the API call method.
AddPatient(columns(iPatIDCol), access_token) ' why an access_token as parameter??
End If
End Function
To be honestOkay so let be honest with you as well...
ApiCallImpl = (Err.Number <> 503)How does that coincide with the following.
You need to query the HTTP result, not the Err object. Err is only populated by an VB(A) runtime error
Modern/Metro style message box and input box for Microsoft Access 2013+
Browse to the paragraph Simulating dialogue mode.