Invalid procedure call or argument
generic-git-user opened this issue · 3 comments
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, thenjson
consists 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 for
first.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.