We help IT Professionals succeed at work.
Get Started

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

99 Views
Last Modified: 2015-11-25
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
    XMLHTTP.Send
    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?

Thanks
Comment
Watch Question
President / Owner
CERTIFIED EXPERT
Fellow
Most Valuable Expert 2017
Commented:
This problem has been solved!
Unlock 1 Answer and 7 Comments.
See Answer
Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

  • Troubleshooting
  • Research
  • Professional Opinions
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE