Unanswered: MultiSelect values in ListBox, Find Values in Record, Click Cmd Button
I have a form which has a listbox that lists all Item ID's currently in the database. The ListBox's Multi-Select is set to Simple. Lets say the user chooses the following Item IDs: 3, 258, and 396. After the user clicks a command button, I want the program to find the records that have those Item ID's and I want them to be displayed in a Continious Form fashion. After that I have a command button that adds all of them to the test. How can a do a loop so that the command button code gets run 3 times in this case?
Well...I suppose you could do something like this in the OnClick event for your button...
Dim CriteriaStrg As Strg
Dim varItm As Variant
For Each varItm In Me.myListBoxName.ItemsSelected
CriteriaStrg = CriteriaStrg & "[myTableIDField] = '" & Me.myListBoxName.ItemData(varItm) & "' OR "
If Right(CriteriaStrg, 4) " OR " then CriteriaStrg = Left(CriteriaStrg, Len(CriteriaStrg) - 4)
Me.Filter = CriteriaStrg
Me.FilterOn = True
Now...keep in mind, this was just quickly composed from the top of my head and was not tested. I think you will get the concept though. You will, of course, need to ensure that the proper column is bound in your ListBox.