Using MS ACCESS and VBA to create REST/JSON file.

Posted on 2014-09-12
Medium Priority
Last Modified: 2014-10-15
I have been programming in VBA/ACCESS for quite a few yrs but new to JSON and REST. I am not able to get to the web-site <https://code.google.com/p/vba-json/> to see the code you are referring to.   Would it be possible to see a sample of your ACCESS Database to understand how to grab the REST data, using JSON?  Thank you very much!!
Question by:vfinato
  • 7
  • 6
  • 2
  • +1
LVL 46

Expert Comment

ID: 40319774
Do you need help with the call to retrieve the data or the parsing of the retrieved data or both?

What is the URL from which you are retrieving the data?
LVL 46

Expert Comment

ID: 40323584
I'm getting a webpage not available message
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!


Author Comment

ID: 40323615
Attached, is a file of the output when I put the URL in a Firefox Browser:
LVL 46

Expert Comment

ID: 40323646
What do you need to get out of those JSON objects?

Author Comment

ID: 40323677
I have never done any web/JSON/REST work w/ MS-ACCESS I am trying to figure out how to do the following:
1. submit a url string using VBA in MS-ACCESS,
2. Retrieve the output from the call that so I can parse the data and do w/ it what I want.
3. How to submit a url string so I can update one of the Parameters for instance in the example below I would like to update the "networkName" value and the "purchaseDate value:

        "id": 1,
        "type": "Asset",
        "assetNumber": "1",
        "contractExpiration": "2014-09-30T07:00:00Z",
        "macAddress": null,
        "networkAddress": null,
        "networkName": null,
        "notes": null,
        "purchaseDate": "2013-12-30T08:00:00Z",
        "serialNumber": null,
        "version": "2010",
        "assetstatus": {
            "id": 2,
            "type": "AssetStatus"
LVL 59

Accepted Solution

Jim Dettman (Microsoft MVP/ EE MVE) earned 1000 total points
ID: 40323700
I'm not sure what the JSON part looks like, but this is an example of calling a web site service and getting a value returned.  This is done with a reference set to Microsoft XML v6.0 lib.


                  ' Capture the CC

                  ' Set the correct URL
                  'strPostURL = "https://test.authorize.net/gateway/transact.dll"
110               strPostURL = "https://secure.authorize.net/gateway/transact.dll"
                  'strPostURL = "https://developer.authorize.net/tools/paramdump/index.php"

120               strPostSting = ""
130               strPostSting = strPostSting & "x_login=" & URLEncode(strAPILogin) & "&"
140               strPostSting = strPostSting & "x_tran_key=" & URLEncode(strTransactionKey) & "&"
                  'For debugging.
                  'strPostSting = strPostSting & "x_test_request=" & URLEncode("TRUE") & "&"
150               strPostSting = strPostSting & "x_version=" & URLEncode("3.1") & "&"
160               strPostSting = strPostSting & "x_delim_data=" & URLEncode("TRUE") & "&"
170               strPostSting = strPostSting & "x_delim_char=" & URLEncode("|") & "&"
180               strPostSting = strPostSting & "x_relay_response=" & URLEncode("FALSE") & "&"
190               strPostSting = strPostSting & "x_email_customer=" & URLEncode("FALSE") & "&"

200               strPostSting = strPostSting & "x_type=" & URLEncode("PRIOR_AUTH_CAPTURE") & "&"
210               strPostSting = strPostSting & "x_trans_id=" & URLEncode(rs!CCTransactionID) & "&"

                  ' Additional fields can be added here as outlined in the AIM integration
                  ' guide at: http://developer.authorize.net
220               strPostSting = left(strPostSting, Len(strPostSting) - 1)

                  ' We use xmlHTTP to submit the input values and record the response
                  Dim objRequest As New MSXML2.XMLHTTP
230               objRequest.Open "POST", strPostURL, False
240               objRequest.Send strPostSting
250               strPostResponse = objRequest.responseText
                  'Debug.Print strPostResponse
260               Set objRequest = Nothing

                  ' the response string is broken into an array using the specified delimiting character
270               arrResponse = Split(strPostResponse, "|", -1)

280               If arrResponse(0) = 1 Then
                      ' Amount was captured.
                      ' Update order import tracking table
290                   strCommand = "UPDATE tblOrdImportTracking SET CCCapturedAt = '" & Now() & " ' WHERE JobNumber = " & !JobNumber & " AND ExportersOrderNumber = '" & !ExportersOrderNumber & "'"
300                   cnn.Execute strCommand, lngRecordsAffected, adCmdText
310                   If lngRecordsAffected <> 1 Then Stop
320               Else
330                   Stop
                      ' Not captured for some reason - email IT alert list.
LVL 46

Assisted Solution

aikimark earned 1000 total points
ID: 40323721
Jim is correct in his assertion that you should use the MSXML2 object.  Here is a simplified version of what Jim posted.  This is my template.
    Dim oXMLHTTP As Object
    Dim strHTML as string
    Set oXMLHTTP = CreateObject("MSXML2.XMLHTTP")
    oXMLHTTP.Open "POST", "https://yourtargetwebsiteURL", False
    oXMLHTTP.Send "your SOAP envelope"
    Do Until oXMLHTTP.ReadyState = 4
    If oXMLHTTP.Status = 200 Then
        strHTML = oXMLHTTP.responsetext
        'add your parsing code here
        'and then push the result into your worksheet
    End If

Open in new window

Do you need all the fields parsed of just some of the fields?

Author Comment

ID: 40323739
I am going to need all the fields parsed

Author Comment

ID: 40323771
What References do I need to set?
LVL 59
ID: 40323795
REST is nothing more than an architectural style for doing a web site.  JSON I believe is just a method of formatting the strings based on some stuff in Java,  but in VBA it all boils down to POST and GET.  I think for the JSON part, you could setup a JSON parser based on it's principles, but I'm not sure you'd need to go that far.  Split works pretty well if your needs are no extensive.

And while that routine I posted looks lengthy, most of it is just setting up the string to pass.  The actual back and forth with the web site is only the couple of lines as Mark showed and which you'll see in the middle of the routine I posted.


Author Comment

ID: 40323890
So if I am understanding this correctly.  I get the data by first building the strPostString.
Then sending the strPostString w/ the objRequest.Open and the objRequest.Send strPostString

Then, I capture the returned data with the  strPostResponse = objRequest.responseText

I then parse out the returned data captured in the strPostResponse variable.
Is my thinking correct?

                Dim objRequest As New MSXML2.XMLHTTP
                objRequest.Open "POST", strPostURL, False
                objRequest.Send strPostSting
                strPostResponse = objRequest.responseText
LVL 46

Expert Comment

ID: 40323964
yes.  That is the basic scheme.

Pushing updates is going to be a bit different.
LVL 46

Expert Comment

ID: 40325988
btw...I don't think that VBA-JSON project is complete.

Author Comment

ID: 40331472
I was able to get the returned data using the above examples, then, parse the data as needed.  Now I need to understand how to update a record.
LVL 50

Expert Comment

by:Martin Liss
ID: 40381693
This question has been classified as abandoned and is closed as part of the Cleanup Program. See the recommendation for more details.

Featured Post

Receive 1:1 tech help

Solve your biggest tech problems alongside global tech experts with 1:1 help.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Implementing simple internal controls in the Microsoft Access application.
A Case Study of using the Windows API to provide RS232 communications capability in Access without the use of Active-X controls.
With Microsoft Access, learn how to start a database in different ways and produce different start-up actions allowing you to use a single database to perform multiple tasks. Specify a start-up form through options: Specify an Autoexec macro: Us…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…
Suggested Courses

621 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question