Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Loop through List 1

Status
Not open for further replies.

jamez05

Programmer
Jul 29, 2005
130
US
Hi, wanted to do a search to see if solution exists, but the search is down. Anyway, I have a field in a table name "MARINEorFRESHWATER". The field can be empty or contain a list separated by colons (i.e freshwater; brackish; marine).

I'm trying to highlight the values in an option box based on the list. I'm not sure how to loop through this list though. The top for loop in the below code is what I'm stuck on:

Code:
If rs.MARINEorFRESHWATER <> "" Then
   'Loop through rs.MARINEorFRESHWATER List
   	For i = 0 To Me.listMarine.ListCount Step 1
           If Trim(Me.listMarine.ItemData(i)) = Trim(Me.listSitesEdit.Column(3, i)) Then
              Me.listClass.Selected(i) = True
           End If
        Next i
   'End List Loop
Else ' Select the empty value
        
End If
 
You use three different list boxes in your code but only indicate one list box in your explanation. Please be more clear.


-V
 
Sorry about that, copied some old code. Here's a clearer picture. I'm concerned with the first loop ('Loop through rs.MARINEorFRESHWATER List):

Code:
If rs.MARINEorFRESHWATER <> "" Then
  'Loop through rs.MARINEorFRESHWATER List
      For i = 0 To Me.listMarine.ListCount Step 1
         'If Trim(Me.listMarine.ItemData(i)) = Trim(ListVal) Then
             'Me.listMarine.Selected(i) = True
          'End If
      Next i
   'End List Loop
Else ' Select the empty value
   Me.listMarine.Selected(0) = True
End If
 
Something like this ?
Code:
i = 0
For Each myItem In Split(rs.MARINEorFRESHWATER, ";")
  If Trim(myItem) = Trim(Me.listSitesEdit.Column(3, i)) Then
    Me.listClass.Selected(i) = True
  End If
  i = i + 1
Next

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
Thanks for everyone's input. Used PHV's idea and got the following working:
Code:
        If rs.MARINEorFRESHWATER <> "" Then
            For i = 1 To Me.listMarine.ListCount - 1 Step 1
                j = 0
                For Each myItem In Split(rs.MARINEorFRESHWATER, ";")
                    If Trim(Me.listMarine.ItemData(i)) = Trim(myItem) Then
                        Me.listMarine.Selected(i) = True
                    End If
                j = j + 1
                Next
            Next i
        Else ' Select the empty value
           Me.listMarine.Selected(0) = True
        End If
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top