MajP
You've got your good things, and you've got mine.
- Local time
- Today, 06:24
- Joined
- May 21, 2018
- Messages
- 9,504
However if I have code that opens the specific database and then the function ends and afterwards I use the snippet of code to close the said database in a separate function, then it doesn't work as it doesn't seem to 'remember' the value of the specific db in MyDict.
Sorry, that is not correct and you can test this quite simply. If I have a module level container and put a pointer in there that pointer remains even if the object reference goes out of scope.
Question. What will happen when I run testscope2?
Code:
Public myDict2 As Dictionary
Public Sub TestScope()
Dim ws1 As Worksheet
Set ws1 = ActiveSheet
Set myDict2 = New Dictionary
myDict2.Add ws1.Name, ws1
'ws1 is out of scope and set to nothing but a pointer exists in myDict2
Set ws1 = Nothing
End Sub
Public Sub testscope2()
'ws1 is out of scope but pointer to active sheet exists
Debug.Print myDict2.Item(myDict2.Keys(0)).Name
End Sub