Solved

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

Posted on 2014-09-12
17
2,412 Views
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!!
0
Comment
Question by:vfinato
  • 7
  • 6
  • 2
  • +1
17 Comments
 
LVL 45

Expert Comment

by:aikimark
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?
0
 

Author Comment

by:vfinato
ID: 40323556
0
 
LVL 45

Expert Comment

by:aikimark
ID: 40323584
I'm getting a webpage not available message
0
 

Author Comment

by:vfinato
ID: 40323615
Attached, is a file of the output when I put the URL in a Firefox Browser:
The-REST-Output.txt
0
 
LVL 45

Expert Comment

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

Author Comment

by:vfinato
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"
        },
0
 
LVL 57

Accepted Solution

by:
Jim Dettman (Microsoft MVP/ EE MVE) earned 250 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.

Jim.

                  ' 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.
0
 
LVL 45

Assisted Solution

by:aikimark
aikimark earned 250 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
        DoEvents
    Loop
    
    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?
0
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 

Author Comment

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

Author Comment

by:vfinato
ID: 40323771
What References do I need to set?
0
 
LVL 57
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.

Jim.
0
 

Author Comment

by:vfinato
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
0
 
LVL 45

Expert Comment

by:aikimark
ID: 40323964
yes.  That is the basic scheme.

Pushing updates is going to be a bit different.
0
 
LVL 45

Expert Comment

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

Author Comment

by:vfinato
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.
0
 
LVL 45

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.
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

I see at least one EE question a week that pertains to using temporary tables in MS Access.  But surprisingly, I was unable to find a single article devoted solely to this topic. I don’t intend to describe all of the uses of temporary tables in t…
Background What I'm presenting in this article is the result of 2 conditions in my work area: We have a SQL Server production environment but no development or test environment; andWe have an MS Access front end using tables in SQL Server but we a…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
Learn how to number pages in an Access report over each group. Activate two pass printing by referencing the pages property: Add code to the Page Footers OnFormat event to capture the pages as there occur for each group. Use the pages property to …

747 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

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now