Can you move highlighted data from one listbox to another listbox on the same form?

C

Col. Forbin

I am bringing back data from a table in a listbox and want to move the
selected records into a blank listbox (or possibly textbox). Is there an
easy way to do this? I also was looking for an arrow button ( >>) to
trigger this data move but have been unsuccessful in my attempt to locate
it.

Thanks for any help...
Matt
 
M

Mike Labosh

I am bringing back data from a table in a listbox and want to move the
selected records into a blank listbox (or possibly textbox). Is there an
easy way to do this? I also was looking for an arrow button ( >>) to
trigger this data move but have been unsuccessful in my attempt to locate
it.

I made a form with two list boxes, lstOne and lstTwo.

lstOne was list-bound to a table and set for Multi Select.

I set the RowSourceType property of lstTwo to Value List.

Then I made a button, cmdMove and gave it >> as a caption. Access has some
arrow icons that are much nicer.

Then I did this (the Requery at the bottom may not be needed):

Private Sub cmdMove_Click()

Dim s As String
Dim i As Integer

For i = 1 To lstOne.ItemsSelected.count
s = lstOne.ItemData(i)
lstTwo.RowSource = lstTwo.RowSource & ";" & s
Next

lstTwo.Requery

End Sub

What this procedure does is copy items from one list box to the next. If
you want to MOVE items, then inside the For Next loop, you would need to
Currentdb.Execute a delete statement on the bout list box, and then requery
that one too.
--
Peace & happy computing,

Mike Labosh, MCSD

Feed the children!
Save the whales!
Free the mallocs!
 
C

Col. Forbin

Thanks Mike!

Mike Labosh said:
I made a form with two list boxes, lstOne and lstTwo.

lstOne was list-bound to a table and set for Multi Select.

I set the RowSourceType property of lstTwo to Value List.

Then I made a button, cmdMove and gave it >> as a caption. Access has some
arrow icons that are much nicer.

Then I did this (the Requery at the bottom may not be needed):

Private Sub cmdMove_Click()

Dim s As String
Dim i As Integer

For i = 1 To lstOne.ItemsSelected.count
s = lstOne.ItemData(i)
lstTwo.RowSource = lstTwo.RowSource & ";" & s
Next

lstTwo.Requery

End Sub

What this procedure does is copy items from one list box to the next. If
you want to MOVE items, then inside the For Next loop, you would need to
Currentdb.Execute a delete statement on the bout list box, and then requery
that one too.
--
Peace & happy computing,

Mike Labosh, MCSD

Feed the children!
Save the whales!
Free the mallocs!
 
Top