Scripting.Dictionary

moke123

AWF VIP
Local time
Today, 05:43
Joined
Jan 11, 2013
Messages
4,708
I've been playing around with dictionaries trying to get a grip on how to use them and what they can do.

I've been trying to declare a public dictionary so that its members are available to other procedures within the module.
It seems to work OK if I add the keys and items using Dict.Add "SomeKey", "SomeValue"

If I try to open a recordset and use Dict.Add "SomeKey", rs!SomeField and If I try to access any member I get an error that the object no longer exists.

Am I missing something? Or is this not possible?
 
From what I found, you will need to store the rs!SomeField in a variable first.
Then use the variable.
Without a data type, dictionary stores a pointer to the memory location instead of memory itself. So that may cause your problem.
 
As I typed my question that thought came to mind but I haven't had a chance to test it yet. Thanks for reply.
That makes sense that once the recordset is set = nothing its no longer available.
It may also explain another error message re: datatype
 
Moke,

Paul Kelly has some youtube videos on various subjects. He is an Excel person(I'm not), but his vba stuff is very good (IMHO). Here's one on Dictionary.
 
You may want to relook at my thread on custom collections. You can take your dictionary and wrap it in a class and make a custom "collection" using a dictionary instead of a collection for the class variable.

This way you can make dedicated
Add
Item
Delete
etc.
Especially if this is tailored to do one thing. You can make get information out of the dictionary easier.
 
Moke, you can add brackets around the recordset field
Dict.Add "SomeKey", (rs!SomeField)
 
@MajP I'm still looking at the challenges. Thats what got me messing around with collections and dictionaries.
@Cronk I think I had tried that but not in the add statement. I'll take another look, thanks.
 
There are a lot of workarounds for this I guess.
Using .value should also work
 

Users who are viewing this thread

Back
Top Bottom