list box transfer

E

Eric

I know alot of you have done this before.

I just want to transfer items selected from one list to another, but am not
sure how to handle the columns.
Both listboxes are two columns with column 1 bound. The id for the record is
hidden in column(0) and the display string in column(1). So far, I have this
on clicking the transfer button:

Private Sub cmdAssignSelected_Click()
' this will only be enabled if there are items selected
Dim varItem As Variant
For Each varItem In lstUnassignedPeople.ItemsSelected
lstAssignedPeople.AddItem varItem
lstUnassignedPeople.RemoveItem varItem
Next varItem

varItem has the index of the selected item; I get that much. AQnd I can see
the values I want by doing this in debug window:
?lstUnassignedPeople.Column(1, varitem)
Bozich, Karen ' the display string
?lstUnassignedPeople.Column(0, varitem)
56 ' her employee id

My question is are AddItem and RemoveItem any good here? How do I
populate/remove the columns in each box?

Sorry if this seems too obvious.

TIA,
Eric
 
D

Dirk Goldgar

Eric said:
I know alot of you have done this before.

I just want to transfer items selected from one list to another, but
am not sure how to handle the columns.
Both listboxes are two columns with column 1 bound. The id for the
record is hidden in column(0) and the display string in column(1). So
far, I have this on clicking the transfer button:

Private Sub cmdAssignSelected_Click()
' this will only be enabled if there are items selected
Dim varItem As Variant
For Each varItem In lstUnassignedPeople.ItemsSelected
lstAssignedPeople.AddItem varItem
lstUnassignedPeople.RemoveItem varItem
Next varItem

varItem has the index of the selected item; I get that much. AQnd I
can see the values I want by doing this in debug window:
?lstUnassignedPeople.Column(1, varitem)
Bozich, Karen ' the display string
?lstUnassignedPeople.Column(0, varitem)
56 ' her employee id

My question is are AddItem and RemoveItem any good here? How do I
populate/remove the columns in each box?

Usually I do this sort of thing by basing both list boxes on a table.
The table contains a field, usually a boolean (yes/no) field, that
identifies which of the two list boxes that record should appear in.
Each list box has as its rowsource a query that applies a criterion on
that field to returns the set of records that should appear in that
particular list box. Then the logic to transfer the selected items from
one list box to another actually updates the boolean field in the table
for each selected item (using a recordset or update query), and then
requeries the two list boxes.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top