Problem with Split() and looping

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Dan2kx
    Contributor
    • Oct 2007
    • 365

    Problem with Split() and looping

    Hello, im trying to use a split function to create an array and then loop thgrough that to select items on a listbox. here is the code

    Code:
    Dim row As Variant, item As Variant, sArray As String
        sArray = Split(SList, ",")
        For Each item In sArray
            For row = 0 To lst1.ListCount - 1
                If Me.lst1 = sArray(1) Then Me.lst1.ItemsSelected = True
            Next
        Next
    Problem is that access says "For Each may only iterate over a collection object or an array"

    Well... it is.... isn't it??

    Can somebody point me in the right way? cheers
  • jimatqsi
    Moderator Top Contributor
    • Oct 2006
    • 1293

    #2
    You've declared sArray as a string, not an array.

    Try dim sArray(n) As String where n is the number of elements you want in the array.

    Jim

    Comment

    • Dan2kx
      Contributor
      • Oct 2007
      • 365

      #3
      Doh, always the obvious mistakes huh
      also changed the loop code

      Code:
      For x = LBound(sArray) to UBound(sArray)
      Cheers fella

      Comment

      Working...