Results 1 to 3 of 3

Thread: List Box

  1. #1
    Join Date
    Feb 2005

    Unanswered: List Box

    I've been working on something for the last 1.5 hours and I cant do it, so I'm back to the forum looking for help.

    I have a list box that populates date from a table, I have the multi select set to simple.

    I want to click a couple of items in the listbox and for a message box to say, you have selected x.x.x.x. etc etc

    It sounds simple to do

  2. #2
    Join Date
    Dec 2004
    Madison, WI
    One way I like to do stuff like this is have a temp table and a listbox on the right side of the form with the rowsource based on the temp table. Then I put 2 arrow buttons between the 2 listboxes on the form, one which points to the left listbox (i.e. remove item) and one which points to the right listbox (i.e. add item). The user clicks an item in the listbox and then clicks the add item button which then runs some code to add that item to temp table and hence, show it on the right listbox. If the user selects an item in the right listbox and then the remove item button, I run code to delete the selected item from the temp table. Then any queries or reports simply join on the temp table to retrieve the records of the items selected.

    Other than that, if you have a listbox where the user selects multiple items, to retrieve the items selected you need to walk through the collection of the listbox, storing the items selected into a variable.

    Dim QItem as string (variable to hold listbox items selected)
    Dim ctlList As Control
    Dim i As Integer
    Set ctlList = me!ListBoxItems
    For i = 0 To ctlList.ListCount - 1
    If ctlList.Selected(i) = True Then
    If QItem = "" then
    QItem = ctlList.ItemData(i)
    QItem = QItem & ", " & ctlList.ItemData(i)
    End if
    End If
    Next i
    msgbox "You have selected the following: " & QItem
    Last edited by pkstormy; 02-18-08 at 18:00.
    Expert Database Programming
    MSAccess since 1.0, SQL Server since 6.5, Visual Basic (5.0, 6.0)

  3. #3
    Join Date
    Nov 2004
    out on a limb
    Provided Answers: 59
    if there are multiple items selected then you may want to use the constant vbcrlf after each selected item to separate lines

Posting Permissions

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