Button to copy listbox values to new listbox

mike2000

Registered User.
Local time
Today, 18:33
Joined
Mar 3, 2003
Messages
15
I found this great bit of code on here. It copies the 1st item (column) of a list box to another list box. The problem is i need it to copy more than one of the columns, about 4 or 5. I'm not VB literate, so i woundered if someone could help me out, if its possible to do it. Many Thanks in advance.

mike

Private Sub Command4_Click()
Dim lst1 As ListBox, lst2 As ListBox
Dim itm As Variant

Set lst1 = Me!List7
Set lst2 = Me!List2
' Check selected items.
For Each itm In lst1.ItemsSelected
' Set RowSource property for first selected item.
If lst2.RowSource = "" Then
lst2.RowSource = 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.ItemData(itm)
End If
End If
Next itm
End Sub
 
Add an iner-loop inside your loop, looping on the number of columns such that

dim icol as integer
for icol = 0 to 3 ' for 4 columns
'simply stated without your testing
lst2.RowSource.column(icol) = lst1.ItemData(itm).column(icol)
next icol

The foregoing ought to give you the idea of what to do.

Note that I commonly use tables or temporary tables as listbox row sources. I don't understand exactly what you're doing with the ";" separator. I've never used that technique.
 
Thanks for the reply, ill give it a go and let you know how i get on.
 

Users who are viewing this thread

Back
Top Bottom