Connect to web service in MS Access with VBA

前端 未结 3 1985
遇见更好的自我
遇见更好的自我 2021-01-02 04:52

Is it possible to connect to a web service (for example send a HTTP Request) via VBA in Microsoft Access? For example, the user clicks a button on a form, t

3条回答
  •  温柔的废话
    2021-01-02 05:42

    This is code I've used quite successfully with Access 2003. It's from the interwebs, copied and re-copied ages ago. It creates a XMLHttpRequest Object, sends an HTTP GET request, and returns the results as a string.

    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
    

    sReq is the URL; the function returns the response. You may need to make sure ActiveX Data Objects are enabled under your References (in the VBA editor, go to Tools > References).

提交回复
热议问题