I am using Access VBA to access movie information using the API. It is working fine but I have a problem with attributes that have as name the word "name" which is a reserved word.
Let's say I want to access the production companies. I am using this code, and it is working fine if I want to get the id, but it doesn't work if I am trying to get the names because the word "name" is a reserved word in line 4.
Does anyone have an idea how to fix it?
The working code:
Set Keys1 = VBA.CallByName(jsonDecode1, "production_companies", VbGet)
movie_companies = ""
For Each Key In Keys1
movie_companies = movie_companies & **key.id** & ","
Next
The not working code:
Set Keys1 = VBA.CallByName(jsonDecode1, "production_companies", VbGet)
movie_companies = ""
For Each Key In Keys1
movie_companies = movie_companies & **Key.Name** & ","
Next
The json file:
production_companies: [ { name: "France 2 Cinéma", id: 83 }, { name: "SBS Productions", id: 8997 }, { name: "Les Films Français", id: 16782 } ],
Thank you for your reply, but i need to give you more details of what i am doing. yes i am using a collection but i didn't create it i am just importing data do the collection from a website using API, also i want to let you know that all the other properties works fine except the "name" may be because the editor capitalize the first letter of the word "Name" automatically but it doesn't capitalize the other words, how can i avoid the editor to capitalize the word "name" maybe that's the issue. Thank you again
That's the whole code:
Set sc = CreateObject("ScriptControl"): sc.language = "JScript"
Set oXMLHTTP1 = CreateObject("MSXML2.XMLHTTP")
oXMLHTTP1.Open "GET", URL, False 'Open socket to get the website
oXMLHTTP1.setRequestHeader "Content-Type", "application/x-www-form-urlencoded; charset=UTF-8"
oXMLHTTP1.send 'send request
Do While oXMLHTTP1.ReadyState <> 4
DoEvents
Loop
oResp = oXMLHTTP1.responseText 'Returns the results as a byte array
Set jsonDecode1 = sc.Eval("(" + oResp + ")")
Set Keys1 = VBA.CallByName(jsonDecode1, "production_countries", VbGet)
For Each Key In Keys1
movie_companies = movie_companies & Key.id & ","
movie_companies = movie_companies & Key.Name & ","
Next
Now i am sure that the problem is the fact that the first letter is uppercase, because i have another property named "key" and because the editor change it to "Key" with uppercase K, it is not working too :) is there a way to disabled changing the first letter to uppercase in the code editor? this will definitely fix the problem