Access JumpStart 2.0 | Blog

A Rapid Development Framework for Microsoft Access

When you want to view the contents of a dictionary object in the VBA locals window, it turns out you just can’t. It shows the Dictionary Items collection with the item number and key contents, but not the value.

In order to see what’s in the dictionary, you need to access it directly in the VBA Immediate window.

Here is a Stack Overflow article about this:

https://stackoverflow.com/questions/9803708/how-to-monitor-the-values-in-a-dictionary-in-the-excel-vba-watch-window

It has a handy one liner you can cut and paste in the Immediate Windows updating it with your dictionary variable name to print out the contents of a simple dictionary:

for each i in dic.Items: debug.Print i: next

And here is a function from the article to print out a nice list of simple elements with nested dictionaries supported as well:

'I use a recursive function which can be used to display all simple type variables and the contents of all nested dictionaries in the watch window. This produces output in the form:

'Fred:rabbit; Tiddles:cat; Fluffy:cat; Food:[1:lettuce; 2:biscuits; ]; 
'where keys and values are separated by ":", items are separated by "; " and nested dictionaries are shown in square brackets.

Public Function DictionaryContents(ByVal dcDictionary, Optional ByVal boolShowKeyIndex As Boolean = False)

  Dim Keys
  Keys = dcDictionary.Keys

  Dim i As Long
  Dim stIndex As String

  Dim stOutput As String
  stOutput = vbNullString

  For i = 0 To dcDictionary.Count - 1

    If boolShowKeyIndex Then
      stIndex = "(" & i & ")"
    End If

    stOutput = stOutput & Keys(i) & stIndex & ":"

    If IsObject(dcDictionary(Keys(i))) Then
      stOutput = stOutput & "[" & DictionaryContents(dcDictionary(Keys(i)), boolShowKeyIndex) & "]"
    Else
      stOutput = stOutput & dcDictionary(Keys(i))
    End If

    stOutput = stOutput & "; "

  Next i

  DictionaryContents = stOutput

End Function