• Status: Solved
• Priority: Medium
• Security: Public
• Views: 214

# Sending items from one listbox to another

Hello,

I was wondering if it's possible to get selected items from one list box and select the same items in another listbox?
0
Yury Merezhkov
1 Solution

Commented:
Loop throught each item in the first listbox and if it is selected...select the same item in the second listbox
0

Thank you, i understand that. But i've just started programming in vb and access :( Sample code would be greatly appreciated.
0

Commented:
0

Commented:

Presuming both lists have the same content in the same order:
---------------------------------------------------
Dim lCnt As Long

' loop through each item in list one
For lCnt = 0 To List1.ListCount - 1

' if item is selected, select same in list two
If List1.Selected(lCnt) Then List2.Selected(lCnt) = True
Next lCnt
---------------------------------------------------
If lists are not same and you want to select item with same text:
---------------------------------------------------
Dim lCnt  As Long
Dim lCnt2 As Long
Dim sTxt  As String

' loop through each item in list one
For lCnt = 0 To List1.ListCount - 1

' check each list two item for same text
If List1.Selected(lCnt) Then
sTxt = List1.List(lCnt)

For lCnt2 = 0 To List2.ListCount - 1

' if item has same text as list one item, select it
If List1.List(lCnt) = sTxt Then List2.Selected(lCnt) = True
Exit For
Next lCnt
End If
Next lCnt

0

Commented:
--Correction--
---------------------------------------------------
If lists are not same and you want to select item with same text:
---------------------------------------------------
Dim lCnt  As Long
Dim lCnt2 As Long
Dim sTxt  As String

' loop through each item in list one
For lCnt = 0 To List1.ListCount - 1

' check each list two item for same text
If List1.Selected(lCnt) Then
sTxt = List1.List(lCnt)

For lCnt2 = 0 To List2.ListCount - 1

' if item has same text as list one item, select it
If List1.List(lCnt) = sTxt Then List2.Selected(lCnt) = True
Exit For
Next lCnt2
End If
Next lCnt
0

Here is my code, and it's not working:

For lCnt = 0 To Me.ClientByDate.ListCount - 1
If Me.ClientByDate.Selected(lCnt) Then
sTxt = Me.ClientByDate.ItemData(lCnt)
For lCnt2 = 0 To Forms!frmFullReport!Client_List.ListCount - 1
If Forms!frmFullReport!Client_List.ItemData(lCnt2) = sTxt Then
Forms!frmFullReport!Client_List.Selected(lCnt2) = True
End If
Next lCnt2
End If
Next lCnt

Any ideas y?

P.S.: List1.List(lCnt) was giving me an error, that's y i used List1.ItemData(lCnt)
0