I have two listboxes (test1 and test2) and 4 buttons (add item, add all, delete item, delete all)
I want the user to be able to select all items and click "add all" and the selected items to jump to the second listbox.
I have it working for add item, delete item and delete all.
The "add all" is giving me a problem, it's only adding one column instead of two.
I also need the items in the second listbox to update the table work_codes
This is for a multi-user system.
Can anyone out there help me? Here's my code:
Private Sub cmdAdd___Click()
Dim lst1 As ListBox, lst2 As ListBox
Dim itm As Variant
Set lst1 = Me.Test1
Set lst2 = Me.Test2
' Check selected items.
For Each itm In lst1.ItemsSelected
' Set RowSource property for first selected item
If lst2.RowSource = "" Then
lst2.RowSource = lst1.Column(0) & "; " & lst1.ItemData(itm)
Else
' Check whether item has already been copied
If Not InStr(lst2.RowSource, lst1.ItemData(itm)) > 0 Then
lst2.RowSource = lst2.RowSource & "; " & lst1.Column(0) & "; " & lst1.ItemData(itm)
End If
End If
Next itm
Me.Test1.Requery
End Sub
Private Sub cmdAddAll_Click()
Dim lst1 As ListBox, lst2 As ListBox
Dim intCnt As Integer
Dim itm As Variant
Set lst1 = Me.Test1
Set lst2 = Me.Test2
lst1.Selected(0) = True
' Check selected items.
For Each itm In lst1.ItemsSelected
' Set RowSource property for first selected item
If lst2.RowSource = "" Then
lst2.RowSource = lst1.Column(0) & " ; " & lst1.ItemData(itm)
Else
' Check whether item has already been copied
If Not InStr(lst2.RowSource, lst1.Column(0) & "; " & lst1.ItemData(itm)) > 0 Then
lst2.RowSource = lst2.RowSource & " ; " & lst1.Column(0) & "; " & lst1.ItemData(itm)
End If
End If
intCnt = intCnt + 1
lst1.Selected(intCnt) = True
Next itm
Me.Test1.Requery
Me.Test2.Requery
End Sub
I want the user to be able to select all items and click "add all" and the selected items to jump to the second listbox.
I have it working for add item, delete item and delete all.
The "add all" is giving me a problem, it's only adding one column instead of two.
I also need the items in the second listbox to update the table work_codes
This is for a multi-user system.
Can anyone out there help me? Here's my code:
Private Sub cmdAdd___Click()
Dim lst1 As ListBox, lst2 As ListBox
Dim itm As Variant
Set lst1 = Me.Test1
Set lst2 = Me.Test2
' Check selected items.
For Each itm In lst1.ItemsSelected
' Set RowSource property for first selected item
If lst2.RowSource = "" Then
lst2.RowSource = lst1.Column(0) & "; " & lst1.ItemData(itm)
Else
' Check whether item has already been copied
If Not InStr(lst2.RowSource, lst1.ItemData(itm)) > 0 Then
lst2.RowSource = lst2.RowSource & "; " & lst1.Column(0) & "; " & lst1.ItemData(itm)
End If
End If
Next itm
Me.Test1.Requery
End Sub
Private Sub cmdAddAll_Click()
Dim lst1 As ListBox, lst2 As ListBox
Dim intCnt As Integer
Dim itm As Variant
Set lst1 = Me.Test1
Set lst2 = Me.Test2
lst1.Selected(0) = True
' Check selected items.
For Each itm In lst1.ItemsSelected
' Set RowSource property for first selected item
If lst2.RowSource = "" Then
lst2.RowSource = lst1.Column(0) & " ; " & lst1.ItemData(itm)
Else
' Check whether item has already been copied
If Not InStr(lst2.RowSource, lst1.Column(0) & "; " & lst1.ItemData(itm)) > 0 Then
lst2.RowSource = lst2.RowSource & " ; " & lst1.Column(0) & "; " & lst1.ItemData(itm)
End If
End If
intCnt = intCnt + 1
lst1.Selected(intCnt) = True
Next itm
Me.Test1.Requery
Me.Test2.Requery
End Sub