Results 1 to 3 of 3
  1. #1
    Ruegen's Avatar
    Ruegen is offline VIP
    Windows 8 Access 2010 64bit
    Join Date
    Jul 2013
    Location
    Australia
    Posts
    1,496

    VBA loop array of dictionary

    Trying to loop through a dictionary in each array - I am storing seperate values but for some reason when I loop the array and try to print the key items inside each dictionary inside each array I get the same values and not different ones - cannot see where I have slipped up in the code...!

    Code:
    rs.MoveFirst
    Do Until rs.EOF
        
        myDict.RemoveAll
        
        myDict.Add "ShowDate", Format(rs!BookingDate, "dd/mm/yyyy")
        myDict.Add "Teacher", Trim(rs!TeacherName & " " & rs!TeacherSurname)
        myDict.Add "ShowTitle", rs!ShowTitle
        myDict.Add "Feedback", rs!Feedback
           
        ReDim Preserve arr(0 To x) As Dictionary
        Debug.Print x
        Set arr(x) = myDict
        Debug.Print arr(x).Item("ShowTitle")
        Debug.Print arr(x).Item("ShowDate")
        x = x + 1
        
        rs.MoveNext
    Loop
    
    
    
    
    For x = LBound(arr) To UBound(arr)
    
    
        Debug.Print x
        Debug.Print arr(x).Item("ShowDate")
    
    
    Next x


  2. #2
    Ruegen's Avatar
    Ruegen is offline VIP
    Windows 8 Access 2010 64bit
    Join Date
    Jul 2013
    Location
    Australia
    Posts
    1,496
    I tried this too - no success...

    Code:
    Dim arr() As Variant, x As Long
    
    
    rs.MoveFirst
    Do Until rs.EOF
    
    
        ReDim Preserve arr(0 To x) As Variant
        
        Set arr(x) = New Dictionary
      
        arr(x).Add "ShowDate", Format(rs!BookingDate, "dd/mm/yyyy")
        arr(x).Add "Teacher", Trim(rs!TeacherName & " " & rs!TeacherSurname)
        arr(x).Add "ShowTitle", rs!ShowTitle
        arr(x).Add "Feedback", rs!Feedback
        
        x = x + 1
        
        rs.MoveNext
    Loop
    
    
    
    
    
    
    For x = LBound(arr) To UBound(arr)
    
    
        With arr(x)
            Debug.Print .Item("ShowDate")
            Debug.Print .Item("Teacher")
            Debug.Print .Item("ShowTitle")
            Debug.Print .Item("Feedback")
        End With
        
    Next x

  3. #3
    Ruegen's Avatar
    Ruegen is offline VIP
    Windows 8 Access 2010 64bit
    Join Date
    Jul 2013
    Location
    Australia
    Posts
    1,496
    I had to make a class object and store the information in those as for some reason arrays can't store separate dictionaries (or at least I don't know how to access them from within).

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Replies: 2
    Last Post: 05-14-2015, 12:24 PM
  2. Replies: 6
    Last Post: 02-10-2014, 07:43 AM
  3. Loop or Array not recognized
    By dvgef2 in forum Forms
    Replies: 6
    Last Post: 05-31-2013, 08:37 AM
  4. Replies: 30
    Last Post: 08-30-2012, 05:14 PM
  5. Dictionary usage
    By Mclaren in forum Access
    Replies: 1
    Last Post: 11-29-2011, 12:52 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
  •  
Other Forums: Microsoft Office Forums