Results 1 to 1 of 1

Thread: Recordset and Dictionary subtleties

  1. #1

    Thread Starter
    New Member
    Join Date
    Jul 2010
    Posts
    5

    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.
    Last edited by JulioCaesar; Jul 27th, 2010 at 11:11 PM.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width