Recordset and Dictionary subtleties
Code:
'Run in Microsoft Access 2007 VBA.
Sub CantUnderstand()
Dim rst As Recordset, dic As New Dictionary, c As Byte
Set rst = CurrentDb.OpenRecordset("SELECT [ArtÃculo] FROM [Faltantes]", dbOpenForwardOnly) 'Recordset 'rst' has more than 5 records.
For c = 1 To 5
dic.Add c, rst(0) 'Field '0' is string-type.
rst.MoveNext
Next c
rst.Close
MsgBox dic.Item(1) '"Error 3420. Object is not valid or has no value." I get this when reading items in Dictionary 'dic'.
End Sub
Hope someone can explain me this odd behavior. Have done many tests. Strange things happen when you write directly from a recordset.field on the item argument of a dictionary.add method.