Results 1 to 3 of 3
  1. #1
    Join Date
    Nov 2003
    Posts
    66

    Unanswered: ListItem vs ItemsSelected - Need help deciphering this MS example....

    Quote from MSAccess97 Help.....
    __________________________________________________ ________

    ITEMSELECTED COLLECTION

    The following example prints the value of the bound column for each selected row in a Names list box on a Contacts form. To try this example, create the list box and set its BoundColumn property as desired and its MultiSelect property to Simple or Extended. Switch to Form view, select several rows in the list box, and run the following code:

    Sub BoundData()
    Dim frm As Form, ctl As Control
    Dim varItm As Variant

    Set frm = Forms!Contacts
    Set ctl = frm!Names
    For Each varItm In ctl.ItemsSelected
    Debug.Print ctl.ItemData(varItm)
    Next varItm
    End Sub
    __________________________________________________ _________

    Could someone tell me how to use Itemselected, (rather than ListItem) to trap the BoundColumn values of multi selections in a list box?

    I need these values to run query's on specific records relating to each selected row in the list box, but have no idea how to manipulate MS's example above.
    They seem to be printing the selected values from the listbox to screen (I think) - but I need to send the values to a textbox that my queries reference.
    By my understanding, 'ListItem' only references the number of the selected row, whereas 'ItemSelected' references the actual values, so I figure that's what I need to use.

    Any help appreciated.
    Cheers
    Dave

  2. #2
    Join Date
    Nov 2003
    Posts
    1,487
    Create the multiline TextBox on your Form. In the OnClick event of your listbox, copy and paste the code below:
    Code:
    Dim varItm As Variant
    
    For Each varItm In Me.myListBoxName.ItemsSelected
       Me.myTextBoxName = Me.myTextBoxName & ctl.ItemData(varItm) & vbNewLine
    Next varItm
    Hope this helps

  3. #3
    Join Date
    Nov 2003
    Posts
    66
    Cheers, but tis ok - don't think the multi-select is the way to go on this at all.
    For each possible value that's passed to the textbox from the list selection, there are about 10 other values that I need to capture for update queries. The textbox value tells the query which records to change, and I take the values from other textboxes populated on the on click event of the list, to tell the query what the updates to make actually are. (This does work!!)
    Can't see how this'd work using multiselect, so I've thought of another way just using individual selections.

    Thanks again!
    Dave

Posting Permissions

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