Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Post selected reocrds of a multi-list to another list

Status
Not open for further replies.

catty1160

Technical User
Mar 10, 2003
38
0
0
US
I have two multi-list in a form. List1 is a unbound multi-list with 3 columns with Simple Multi-Selceted property: It look like this:

Column1(ID) Column2(Name) Column3(Price)

1 Item1 $5
2 Item2 $6
3 Item3 $7
4 Item4 $8

I like to choose Item1 and Item4 from the List1, click on a command button (cmd_PostToList2), The original empty bounded List2 will be populated with the 3 columns data of Item1 and Item4. How can I get htis done?
 
Try the following code...

Private Sub cmdPostToList2_Click()
cSelected = ""
For Each Item In List1.ItemsSelected
For nCol = 0 To 2
cSelected = cSelected & List1.Column(nCol, Item) & ";"
Next
Next
List2.RowSource = cSelected
End Sub
 
Hi, Jromeroc:

Sorry for getting back so late. I was messing around and forget this thread.

The code works great. I tried to understand the code, but still not quite get the whole thing (I am beginner in VB).
Can you explain to me these lines:

cSelected = "" (Why two double quotes here?)
..
cSelected = cSelected & List1.Column(nCol, Item) & ";"
(What does this line mean and why double quotes with a semicoloun in the end?)

Again, thank you for help.

Catty



 
Hi, catty1160


cSelected = "" (Why two double quotes here?)

Just initializing the variable to a empty string.



cSelected = cSelected & List1.Column(nCol, Item) & ";"
(What does this line mean and why double quotes with a semicoloun in the end?)


An unbound listbox (or combobox) can be populated using a string with the required values separated with semicolons:

list2.rowsource = "item1;item2;item3"

The previous code takes the values of the three columns (0 to 2) of every selected item in List1 and concatenate this values into a string variable (cSelected) to be used as the rowsource of List2. Maybe you can understand better the code adding a msgbox like this (just for testing):

...
For nCol = 0 To 2
cSelected = cSelected & List1.Column(nCol, Item) & ";"
MsgBox cSelected
Next
...
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top