Results 1 to 6 of 6
  1. #1
    3 Star Lounger
    Join Date
    Jan 2001
    Location
    USA
    Posts
    386
    Thanks
    0
    Thanked 0 Times in 0 Posts

    MultiSelect ListBax (Access 2003)

    I have a multiselect listbox on my form. When I select a value, 1 or multiple, these values update a text box on the form. I am storing the ID of the list item in my table based on the value(s) in the text box.

    What I need some help with is highlighting the selected items when I return to a record. My search form repopulates the values to the other fileds on the form. I would like to have the items show in the listbox as selected if the ID for that item is in the requestType filed.

    Does anyone have a code sample that would help me mark items as selected when redisplaying the form with data recalled from the table?


    Thanks for any help
    Richard

  2. #2
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: MultiSelect ListBax (Access 2003)

    How do you store multiple selected items in the table? (Please provide a detailed answer)

  3. #3
    3 Star Lounger
    Join Date
    Jan 2001
    Location
    USA
    Posts
    386
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: MultiSelect ListBax (Access 2003)

    the listbox has two coulmns, ItemID and Description. ItemID is hidden from the user.
    I am storing the itemID in a single filed seprated by a semi-colon. (ex. 3;6;8;12)
    This string is built in the LostFocus event of my list box and held in a text box on the form until the user clicks the Save button.
    It is then populated to the table field.
    Richard

  4. #4
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: MultiSelect ListBax (Access 2003)

    Personally, I would have stored the selected ItemIDs in a separate table, with a record for each ItemID. But anyway...

    You can use the On Current event of the form to select the appropriate items. In the following, the list box is named lbxSomething and the field holding the semicolon-separated list is named SelItems.
    <code>
    Private Sub Form_Current()
    Dim strList As String
    Dim i As Integer
    strList = ";" & Me.SelItems & ";"
    For i = 0 To Me.lbxSomething.ListCount - 1
    Me.lbxSomething.Selected(i) = _
    (InStr(strList, ";" & Me.lbxSomething.ItemData(i) & ";") > 0)
    Next i
    End Sub
    </code>
    The code loops through the items of the list box and compares the value in the hidden first column to the list of items to be selected.

  5. #5
    Gold Lounger
    Join Date
    Jun 2001
    Location
    Crystal Beach, FL, Florida, USA
    Posts
    3,436
    Thanks
    1
    Thanked 34 Times in 34 Posts

    Re: MultiSelect ListBax (Access 2003)

    I agree with Hans, I would have created a separate table to store these items. Other than showing the items in a listbox, how do you use the information you've stored in that field? It would require considerable effort merely to show this information on a report!
    Mark Liquorman
    See my website for Tips & Downloads and for my Liquorman Utilities.

  6. #6
    3 Star Lounger
    Join Date
    Jan 2001
    Location
    USA
    Posts
    386
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: MultiSelect ListBax (Access 2003)

    That did the trick

    Thanks for your help.
    Richard

Posting Permissions

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