upsert
upsert

Reputation: 9

dict object failing in VBA code

I have following code in vba to populate a dictionary object.

Do
    If Not dict.Exists(rst![key]) Then
       dict.Add rst![key], rst![val]
    End If
    rst.MoveNext
Loop Until rst.EOF

For some reason my dictionary fails, does not add another item to the dictionary, after the first iteration. Please let me know if anybody has any thought on this.

Upvotes: 0

Views: 91

Answers (1)

user353gre3
user353gre3

Reputation: 2755

While using a dictionary object, you have to use the Value property of your recordset in your Dictionary.Add method, otherwise it will not work. Try following

Do
    If Not dict.Exists(rst![key].Value) Then
       dict.Add rst![key].Value, rst![val].Value
    End If
    rst.MoveNext
Loop Until rst.EOF

Upvotes: 1

Related Questions