Results 1 to 5 of 5
  1. #1
    4 Star Lounger
    Join Date
    Feb 2008
    Location
    United Kingdom
    Posts
    490
    Thanks
    0
    Thanked 0 Times in 0 Posts
    I have two listboxes. The first list enables selection of items. The selected items get put into a second listbox.

    The code works well in transferring items, however the second listbox has the ability to change the order of rows. This again works okay. Problem is if another item is selected in the first listbox, it refills the second listbox knocking out the sorted list because the first list creates an array (rowsource) for the second listbox.

    How can I simply pass the row value from one list to another, obviously I will have to cycle through the second list box to make sure the item is not duplicated. I have tried Me.Listbox1b=Me.Listbox1.value, Me.Listbox1b=Me.Listbox1.Column(0,1) etc including the listindex of Listbox1, but just cannot seem to find the syntax.

    Many thanks

    While writing, if an item is selected then unselected in the first listbox, how do I sort that out. So easy with a pen and paper!

  2. #2
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts
    [quote name='ZOR' post='764140' date='08-Mar-2009 09:35'][/quote]
    Don't use a list of values as row source but a query or SQL statement that is sorted by a field. After adding or removing a record, requery the list box to update the display.

  3. #3
    4 Star Lounger
    Join Date
    Feb 2008
    Location
    United Kingdom
    Posts
    490
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Thanks Hans. I did a reply but it went into nowhere?

    I will follow your suggestions. How do I get the value from a row selected on a multiselect list.

    Thanks again for your help. Regards

  4. #4
    4 Star Lounger
    Join Date
    Feb 2008
    Location
    United Kingdom
    Posts
    490
    Thanks
    0
    Thanked 0 Times in 0 Posts
    I managed to get the output from my selected row.

    I now have a seperate problem, I am trying to remove a row item in Listbox1B.

    With Me![ListBox1]
    If .Selected(.ListIndex) = 0 Then
    ' Need to remove item table
    Rst.FindFirst "Item = " & Chr(34) & Me.ListBox1.ItemData(Me.ListBox1.ListIndex) & Chr(34)
    If Rst.NoMatch Then
    ' Do nothing, item not in table
    Else
    Rst.Delete

    ' Need to delete item from Listbox1b
    For TY = 0 To Me.ListBox1B.ListCount - 1
    If Me.ListBox1B.ItemData(Me.ListBox1B, TY) = Me.ListBox1.ItemData(Me.ListBox1.ListIndex) Then
    ' Remove list item code to go in here
    End If
    Next

    End If


    It does not like the line:
    If Me.ListBox1B.ItemData(Me.ListBox1B, TY) = Me.ListBox1.ItemData(Me.ListBox1.ListIndex) Then

    Any suggestions on why the line fails? Thanks

  5. #5
    4 Star Lounger
    Join Date
    Feb 2008
    Location
    United Kingdom
    Posts
    490
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Managed to fix it, thanks

    ' Need to delete item from Listbox1b
    For TY = 0 To Me.ListBox1B.ListCount - 1
    If Me.ListBox1B.ItemData(TY) = Me.ListBox1.ItemData(Me.ListBox1.ListIndex) Then
    Me.ListBox1B.RemoveItem Me.ListBox1B.ItemData(TY)
    End If
    Next

Posting Permissions

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