Results 1 to 3 of 3
  1. #1
    Lounger
    Join Date
    Sep 2001
    Posts
    41
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Multiselect list to show more than one column. (A2K Pro)

    I have a form with two list boxes, plus an add and remove button. The students ID, first and last name are in one list and the buttons move them back and forth to a selected list. But....it only adds the Bound column with the ID. How do I code it to also add to the selected list on the same row, the first and last name of the student.

    I have included the ADD button code.

    Private Sub cmdAddButton_Click()
    Dim StudentListCounter As Integer, StudentCurrentCounter As Integer
    Dim StudentListItems As Integer, StudentCurrentItems As Integer
    Dim ListStr As String, FoundInList As Integer
    StudentListItems = [lstActiveStudents].ListCount - 1
    StudentCurrentItems = [lstSelectedStudents].ListCount - 1
    For StudentListCounter = 0 To StudentListItems
    If [lstActiveStudents].Selected(StudentListCounter) = True Then
    If IsNull([lstSelectedStudents].RowSource) Then
    ListStr = [lstActiveStudents].Column(0, StudentListCounter) & ";"
    [lstSelectedStudents].RowSource = ListStr

    Else
    FoundInList = False
    For StudentCurrentCounter = 0 To StudentCurrentItems
    If [lstSelectedStudents].Column(0, StudentCurrentCounter) = [lstActiveStudents].Column(0, StudentListCounter) Then
    FoundInList = True
    End If
    Next StudentCurrentCounter
    If Not FoundInList Then
    ListStr = [lstSelectedStudents].RowSource & [lstActiveStudents].Column(0, StudentListCounter) & ";"
    [lstSelectedStudents].RowSource = ""
    [lstSelectedStudents].RowSource = ListStr
    End If
    End If
    End If
    Next StudentListCounter
    End Sub

  2. #2
    Lounger
    Join Date
    Jan 2001
    Location
    Pennsylvania, USA
    Posts
    36
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Multiselect list to show more than one column. (A2K Pro)

    The key to your problem lies in how many columns you have defined for your "selected" listbox. Also the "selected" listbox is a list of values, the ColumnCount property defines how many consecutive values are displayed in each row.

    Fox example, if you have the values "a", "b", "c", "d", "e" and "f" defined as your RowSource, having ColumnCount=1 displays a list like this:

    a
    b
    c
    d
    e
    f

    However, having ColumnCount=3 displays a list like this:

    a b c
    d e f

    So, if you concatenate all three columns of your "active" list box together into your "selected" listbox you should solve your problem:

    ListStr = [lstSelectedStudents].RowSource & [lstActiveStudents].Column(0, StudentListCounter) & ";" & [lstSelectedStudents].RowSource & [lstActiveStudents].Column(1, StudentListCounter) & ";" & [lstSelectedStudents].RowSource & [lstActiveStudents].Column(2, StudentListCounter) & ";"

    By the way, if the "active" list is long, it may be more efficient to use the Selected collection of the list box instead of walking EVERY row and checking to see if Selected=True:

    Dim varItem as Variant

    For Each varItem in [lstActiveStudents].Selected
    .....
    ListStr = [lstActiveStudents].Column(0,varItem) & ","
    ...
    Next varItem

  3. #3
    Lounger
    Join Date
    Sep 2001
    Posts
    41
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Multiselect list to show more than one column. (A2K Pro)

    Thank you for your time, I understand the process much better.

Posting Permissions

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