Results 1 to 7 of 7
  1. #1
    Join Date
    May 2007
    Posts
    74

    Unanswered: Multi-Select Listbox population question

    Hi -

    I have a form where I want to display & populate a multi-select listbox. There is a table that will feed the values that will be displayed in the listbox.

    When another field is selected on the form, I want to run a query based on that field that will highlight the previously selected values in the listbox (So that the listbox will look like it did when the user made their original selections from the listbox).

    Is this possible?

    Thanks!

    azjazz

  2. #2
    Join Date
    May 2005
    Posts
    1,191
    Quote Originally Posted by azjazz
    When another field is selected on the form, I want to run a query based on that field that will highlight the previously selected values in the listbox (So that the listbox will look like it did when the user made their original selections from the listbox).
    What has made the values change? How are you storing the "previously selected values"?
    Me.Geek = True

  3. #3
    Join Date
    Feb 2004
    Location
    Chicago, IL
    Posts
    1,312
    You won't be able to do it with a query. The only way you will be able to do it is with VBA.

  4. #4
    Join Date
    May 2007
    Posts
    74
    Quote Originally Posted by nckdryr
    What has made the values change? How are you storing the "previously selected values"?
    I'll have an intermediate cross-reference table (an XhasY table) that will be populated when the user makes their original selections. I want to highlight the selections that they made previously.

    Quote Originally Posted by DCKunkle
    You won't be able to do it with a query. The only way you will be able to do it is with VBA.
    I suspected as much, but I'm not even sure if that is possible. That's why I'm lookin' for help!

    azjazz

  5. #5
    Join Date
    May 2005
    Location
    Nevada, USA
    Posts
    2,888
    Provided Answers: 6
    It's certainly possible, with VBA as DCKunkle already mentioned. Searching here on "multiselect" should turn up the code. The code to save the selected values is commonly used. Many people seem to only use the listbox to select the values initially, then use a subform for subsequent display or editing. However, you can also reselect the listbox items as you've described. That code should also be turned up by a search.
    Paul

  6. #6
    Join Date
    Feb 2004
    Location
    Chicago, IL
    Posts
    1,312
    Here is some code that shows how to use a multi-select listbox. This is code to clear all the selected items in a listbox:

    Code:
        Dim varSelected As Variant
    
        For Each varSelected In Me.lstMailings.ItemsSelected
        
            Me.lstMailings.Selected(varSelected) = False
            
        Next varSelected
    I know you want to do the opposite but this shows how to loop through each item in a listbox.

    Another tip I would suggest, add more fields to your listbox. Even if you are only displaying one field to the user, you can have a number of fields that are 'hidden'. You could have the list box linked to a query that has a PrevioulsySelected column that is hidden in the listbox then loop through the items and mark the ones that were selected before as selected now.

    To reference other columns in a list box use this code:

    Code:
        For Each varSelected In Me.lstMailings.ItemsSelected
        
             lngMailingTypeID = Me.lstMailings.Column(0, varSelected)
            AddMailingToActionList lngMailingTypeID, strBatch, Me.chkMarkMailings, Me.txtPath
            
        Next varSelected
    This example has a hidden column (the primary key, autonumber field) in a hidden column. The field is the Mailing Type ID and the Mailing Type Name is displayed for the user.

  7. #7
    Join Date
    May 2007
    Posts
    74
    Thanks for the responses, guys!

    DCKunkle - From your example, I'm expecting that if I set the .Selected attribute to "True", it will highlight my previous selections. That's what I was looking for.

    I like the "hidden field" concept, but I may have to highlight based upon a query instead.

    The first selection that the user will be making will be a "type", which will then show which items in the listbox were selected previously. If the "type" is a 1->Many, I may still be able to use the hidden field to store the "type" in the previously selected sub-items.

    Hmmm ... good suggestions!

    azjazz

Posting Permissions

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