I have a simple PHI restful service to perform CRUD actions om a MYSQL database, with an Excel workbook acting as the UI.
Opening the workbook fires a GET request to the api which works fine and the current data is displayed on the User Form. I have then controls which allow the user to update and add new records. Which return responses from the Server and i can see that the database has updated.
The issue is that when i fire subsequent GET request I only get the original dataset without any of the changes to the underlying data.
It is only when I close Excel and re-open the Workbook that i get the new data returned to me?
I have ensured that all variables content relating to the API call are destroyed after use and the variable containing the data is set to nothing before the call so that the form cannot be populated with 'old' data.
I have also placed debugging messages on the server side and it only registers the intial GET. Despite stepping through the request on the VBA side in debugger it does not appear that the GET request reaches my server.
I have also tested the Server by calling the page in the browser and i can see the JSON with my new data in it.
Sub getData()
Dim ws As Worksheet
Dim jsonText As String, sUrl As String, response As String
Dim xmlHttp As New MSXML2.XMLHTTP60
Dim JSON As Dictionary
Dim i As Long
Dim Item As Object
Dim comp As Dictionary
Set var = Nothing
Set JSON = Nothing
response = ""
sUrl = "http://xxxxxxxxxxxxxxxxxxxxxxxx"
With xmlHttp
.Open "GET", sUrl, False
.Send
End With
response = xmlHttp.ResponseText
Debug.Print response
Set JSON = JsonConverter.ParseJson(response)
ReDim var(JSON("records").Count, 5)
i = 0
For Each comp In JSON("records")
var(i, 0) = comp("CompId")
var(i, 1) = comp("CompName")
var(i, 2) = comp("Address1")
var(i, 3) = comp("Address2")
var(i, 4) = comp("Address3")
var(i, 5) = comp("PostCode")
i = i + 1
Next
Set xmlHttp = Nothing
Debug.Print "finished"
End Sub
No error messages. Everything appears to be functioning apart from the fact that the new data is not returned until i re-open Excel.
Any pointers gratefully received. Code edited so as to appear in proper way