Listbox (Add & Removed selected items form one listbox to another listbox)

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Aaitaman Tamang
    New Member
    • Jul 2011
    • 22

    Listbox (Add & Removed selected items form one listbox to another listbox)

    Hi everybody,

    I have two listbox in my form, the name of listbox is “ListBox1” and another is “ListBox2”. The ListBox1 Row Source Type is (Table/Query) where users will see all the employee Badge number and name. The column count is (2) and multi select is (Simple)
    Now I have another ListBox which name is (ListBox2) in the same form. I also have selected the Column Count 2 and multi select is (Simple). Now my aim to create two button called (Select Employee) and (Remove Employee)

    I want code behind the two buttons which move selected items form the ListBox1 to ListBox2, and similar code to remove selected items from the ListBox2.

    Appreciated your help
  • Seth Schrock
    Recognized Expert Specialist
    • Dec 2010
    • 2965

    #2
    Without more information, I can do little but point you in the direction I think that you need to go.

    For the remove employee part... You will need to create a delete query to delete the records from the table that contains the employee information. The delete query will use the list box as the criteria for which records to delete.

    For the Select employee part... What do you mean by select the employee? Clicking on the name in the list box selects it.

    For a more detailed response, I need more information such as the SQL code for the row source query (in code tags [the pound sign to the left of the undo button]), which column the list boxes are bound to, and whether or not the employee badge number is the primary key. Also, your title seems to ask a different question then is asked in the text of your question. Are you trying to transfer records from one list box to another or are just trying to delete the records?

    Comment

    • Aaitaman Tamang
      New Member
      • Jul 2011
      • 22

      #3
      Seth,

      Thanks a lot for response. as you required, the ListBix1 is bound to "EmpT" and the second ListBox2 is not bound to anywhere. Yes, I am trying to transfer items from one list box to another list box by using pointing right and left Command buttons.
      Any Help?
      Thanks,

      Comment

      • Seth Schrock
        Recognized Expert Specialist
        • Dec 2010
        • 2965

        #4
        What tables are behind the two list boxes? What are the primary key fields of those tables? Again, I need the SQL code that is the row source of the list boxes.

        Comment

        • ChrisPadgham
          New Member
          • Jan 2012
          • 11

          #5
          Create a button captioned Add

          Code:
          Private Sub cmdAdd_Click()
          On Error GoTo Err_cmdAdd_Click
          
          If Me.List1.ListIndex >= 0 Then
              Me.List2.AddItem Me.List1.ItemData(Me.List1.ListIndex)
          End If
          
          Exit_cmdAdd_Click:
              Exit Sub
          
          Err_cmdAdd_Click:
              MsgBox Err.Description
              Resume Exit_cmdAdd_Click
              
          End Sub
          for remove

          Code:
          Private Sub cmdRemove_Click()
          If Me.List2.ListIndex >= 0 Then
              Me.List2.RemoveItem Me.List2.ListIndex
          End If
          End Sub

          Comment

          • Aaitaman Tamang
            New Member
            • Jul 2011
            • 22

            #6
            Chris,

            Thanks a lot, It works fine. Much appreciated

            Have a great day!

            Comment

            Working...