Results 1 to 3 of 3
  1. #1
    Join Date
    May 2004

    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?

    Thank you!

  2. #2
    Join Date
    Nov 2003
    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 "
    Next varItm
    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.

  3. #3
    Join Date
    Apr 2003
    Alabama, USA
    I've got a sample that shows how to get the selections in a multiple selection listbox here.

    The Access Web has sample code on using selections from a multiple-selection listbox as query parameters. See here.
    Last edited by Cosmos75; 02-24-05 at 22:55. Reason: Updated link

    You live and learn. At any rate, you live. - Douglas Adams

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts