Looping Through Listbox

Elana

Registered User.
Local time
Today, 03:01
Joined
Apr 19, 2000
Messages
232
Loop through list box contents help needed

I've got a list box that shows all locations for a particular owner (as selected in another combo box on my form). I want to be able to programatically determine whether any of the locations shown in the listbox are in California.

Here is my SELECT statement for the contents of the list box.

SELECT tblBuildings.ID, tblLocations.LocName, tblBuildings.Address, tblBuildings.City, tblBuildings.ST, tblLocations.OwnerID FROM tblLocations INNER JOIN tblBuildings ON tblLocations.LocID = tblBuildings.LocNo WHERE (((tblLocations.OwnerID)=[forms]![frmPrintMenu]![cmbselectowner]));

So, how do I loop through the list box contents to find whether CA is in any of the items in the list in field tblBuildings.ST.?

Just a nudge in the right direction to get me started with the code will be greatly appreciated...I'm just having trouble figuring out where I need to start.

Thanks much
 
Elana,
Something like this should work:
Code:
Private Sub cmdTest_Click()
    For i = 0 To lstTest.ListCount - 1
        If lstTest.Column(4, i) = "CA" Then
            ' Do some stuff
        End If
    Next i
End Sub
Remember columns and rows in a listbox start at 0.

Dave
 
Thanks - that works great!
 

Users who are viewing this thread

Back
Top Bottom