连接到Web服务使用VBA的MS Access [英] Connect to web service in MS Access with VBA
问题描述
是否有可能通过VBA的的的Microsoft Access连接到Web服务(例如发送一个HTTP请求)?
例如,用户点击窗体上的按钮,然后一个HTTP请求发送到与确定
。
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, then a HTTP Request is sent to a web service that responds with OK
.
有没有人这样做过?
注:VBA,不是VB.NET
Note: VBA, not VB.NET.
推荐答案
这是code我用很成功地进入2003年,是由interwebs,复制和再复制久远。它创建了一个 XMLHtt prequest对象,发送HTTP GET请求,并返回结果作为字符串
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的网址;该函数返回的响应。您可能需要确保ActiveX数据对象被你参考下启用(在VBA编辑器,选择工具>参考)。
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).
这篇关于连接到Web服务使用VBA的MS Access的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!