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
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Independent Software Vendors: 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 58

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 58
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 49

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

Enroll in August's Course of the Month

August's CompTIA IT Fundamentals course includes 19 hours of basic computer principle modules and prepares you for the certification exam. It's free for Premium Members, Team Accounts, and Qualified Experts!

Question has a verified solution.

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

This article describes a method of delivering Word templates for use in merging Access data to Word documents, that requires no computer knowledge on the part of the recipient -- the templates are saved in table fields, and are extracted and install…
Traditionally, the method to display pictures in Access forms and reports is to first download them from URLs to a folder, record the path in a table and then let the form or report pull the pictures from that folder. But why not let Windows retr…
Using Microsoft Access, learn some simple rules for how to construct tables in a relational database. Split up all multi-value fields into single values: Split up fields that belong to other things into separate tables: Make sure that all record…
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …
Suggested Courses
Course of the Month8 days, 22 hours left to enroll

765 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