VBA - MS Access: Sub providing the repetitive/same results despite changing variables

So I'm working with a PHP API you see, and when a button is clicked I want it to send an HTTP request and get the result (which is only a few words at max)

I load the onclick method up with this code:
Private Sub cmdButton_Click()
    Dim Response As String
    Dim Protocol As String
    Dim Message As String
    Response = http_Resp("http://blahblahblah.blah&API&Variable=" & Me.Variable)
    Message = Response
    MsgBox Message
    Response = ""
    Protocol = ""
    Message = ""
End Sub

Public Function http_Resp(ByVal sReq As String) As String

    Dim byteData() As Byte
    Dim XMLHTTP As Object

    Set XMLHTTP = CreateObject("MSXML2.XMLHTTP")

    XMLHTTP.Open "GET", sReq, False
    byteData = XMLHTTP.responseBody

    Set XMLHTTP = Nothing

    http_Resp = StrConv(byteData, vbUnicode)

End Function

Open in new window

The first time I press said button, there is a slight (expected) delay until the message box pops up. When it does pop up, it shows the appropriate response. However, when I click the button again, there is virtually no wait time and it pops up with the exact same response.

This is troublesome because in my case: 2 consecutive calls to the API DOES result in 2 different responses.
I am certain it is not the API's fault because if I do this manually (ie, go into the browser and go to "blahblahblah.blah") I get the expected differing responses per every refresh.

The fact that the first click makes a delay and the second (or anything after) does not have a delay makes me wonder if the VBA/MS Access is just caching the result for the Sub/Function.

I'm frustrated because this is the first language I have used that flat out skips lines code. The only way I can get the next/different result is if I completely close out of MS Access and open it back up again then click said button.
What am I doing wrong?

Brandon GarnettAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Try adding a loop to wait till the page has responded.
XMLHTTP.Open "GET", sReq, False
Do Until XMLHTTP.readyState = 4: DoEvents: Loop

I also check the status code:
    Do Until oXMLHTTP.ReadyState = 4
    If oXMLHTTP.Status = 200 Then
        strHTML = oXMLHTTP.responsetext
        'add your parsing/processing code here
    End If

Open in new window

Jim Dettman (Microsoft MVP/ EE MVE)President / OwnerCommented:
And a little debugging help:

1. Place a STOP or breakpoint (f9 while on a line of code)
2. Execute
3. Use F8 to single step through.
4. Hover to inspect variables, or Ctrl/G to bring up debug window and then:

? <variable>

 To print it in the window.

5. F5 will continue execution from a break.

 Looks like Ron has you pointed in the right direction though.

Your Guide to Achieving IT Business Success

The IT Service Excellence Tool Kit has best practices to keep your clients happy and business booming. Inside, you’ll find everything you need to increase client satisfaction and retention, become more competitive, and increase your overall success.

Gustav BrockCIOCommented:
Sounds like the page is cached.
Try sending another request (a different value of Me.Variable) and then the first again.

Jim Dettman (Microsoft MVP/ EE MVE)President / OwnerCommented:
um...might need to use POST rather than a GET.


Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Brandon GarnettAuthor Commented:
This worked.

Why does the page cache using GET and not using POST? I have no idea.
Page caching is part of GET.  One of the reasons POST is more secure, aside from the data parameters not being in the URL string, is that it doesn't cache.

It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft Access

From novice to tech pro — start learning today.