Dictionary Basics

ID266
Link ReferenceNot set
Link CreditsNot set
Link Technical DocumentationNot set
PlCodelangMS Access VBA
PlGroupArray
PlItemTitleDictionary Basics
Code' empty dict
Dim myDict As Dictionary
Set myDict = New Dictionary

' some static values
myDict.Add "key1", "value1"
myDict.Add "key2", "valueY"
myDict.Add "keyX", "value98"

' update a key programmatically
myDict.Remove "key1"
myDict.Add "key1", "new value"

' iterate
Dim strKey As Variant
Dim current_key As String
Dim strValue As String
For Each strKey In myDict.Keys()
current_key = strKey
strValue = myDict.Keys(strKey)
Next

' Exists
If myDict.Exists(strKey) Then
Debug.Print "yes"
End If

' get an specific item
Dim subdict As String
subdict = myDict.Keys("key2")
# valueY
Result Example