VBA-tools/VBA-JSON

Invalid procedure call or argument

generic-git-user opened this issue · 3 comments

I saw one other post on this issue but the solution hasn't worked for me. I am able to successfully pull the json data and print it but when I attempt to access one of the specific keys I get this error. I'm on a mac using the dictionary.cls file also.

Screen Shot 2023-12-17 at 12 03 54 PM

Correct on all points! :) Thanks for the quick response.

Your screenshot does not show which statement is causing the error (the yellow highlight when you press Debug). I'm guessing it's the Debug.Print json("id").

If the data starts as shown in the Immediate window, thenjsonconsists of a VBA Collection (JSON Array) of VBA Dictionaries (JSON Object).

So your debugging print should probably look like

    Debug.Print "Found"; json.Count ; "records"
    For Each dict in json
        Debug.Print dict.Item("id")
    Next

Note 1: Your function returnssResult, notjson. I assume that in production, parsing will be done later after error checking.

Note 2: Collection items can be accessed by key, provided that the key was specified when the item was added. But VBA-JSON does not do this. The error 5 in this case effectively means 'key not found'.

Andrew:

  • The first item of a Collection has index 1.
  • The user is on a Mac. So Dictionary, not Scripting.Dictionary.
  • +1 forfirst.Item("id"). VBA-Dictionary can sometimes give a 438 error if you omit normally defaulted methods/properties (Keys, Item).

===================
If this solves your problem, please close the issue here.