Once you have created a SOAP-based API/web service, you can create a client to connect to that service. This document explains how to create a Microsoft Access client, but it is also possible to create a client in many other platforms, including any .NET technology, PHP, Perl, etc. Most of the code presented here can be easily adapted to work with other Microsoft Office products.
Note that the SOAP client used in Microsoft Office may not be able to handle complex SOAP services, so you may experience unexpected or inconsistent results in certain cases, even when .NET or PHP applications are able to interact with the SOAP service without any problems.
- A SOAP web service running on a web server.
- Microsoft Access 2003
- Microsoft Core XML Services (MSXML) 6.0 library (free download)
The example provided below assumes that the SOAP service:
- is properly configured
- returns results as string
- has functions named GetAllContactNames and GetContactByID capable of returning a list of contacts and individual contacts, respectively
For information on creating such a web service, see How to Create a SOAP Web Service with Visual Studio .NET.
- Dowload and install the Web Services Toolkit for Microsoft Office 2003, v.2.01 or later. This is mandatory.
- Create a new Microsoft Access database.
- Enter the code window by create a new module in the database or using ctl-G.
- From the Tools menu, select "Web Service References".
- Select the "Web Service URL" option, and enter the URL of the WSDL file that defines the SOAP web service you want to access, e.g., http://example.com/metrixapi/metrix.asmx?WSDL. The toolkit will use the WSDL file to generate a class that you will be able to access directly in your VBA code. Note that the class and method names generated will not exactly match the methods described in the WSDL file. The web services toolkit add special prefixes to class and method names.
Accessing the Web Service
- Create a form.
- Add a text box named txtID, a text box named txtResults, and a button named cmdSearch.
- For the On Click event of cmdSearch, add this code:
Private Sub cmdSearch_Click()
Dim objClient As New clsws_metrix
'assumes that SOAP service returns strings
If If Nz(Me!txtID.Value) = 0 Then
'show all contacts
Me.txtResults.Value = objClient.wsm_GetAllContactNames
'show only the contact specified
Me.txtResults.Value = objClient.wsm_GetContactByID(Me.txtID.Value)
- View your form in Form View. Clicking the cmdSearch button should return a list of all contacts in the database. Entering a numerical value in txtID and clicking cmdSearch should return the name of the contact corresponding to that ID.