listbox to listbox

  • Thread starter Thread starter JohnE
  • Start date Start date
J

JohnE

I have a mainform (FormA). On it is a listbox on a page
of a tab control. Also on the main form is a button that
will display a popup type form (FormB) with a list box
showing the results of a SELECT statement. From the list
box on FormB I would like to have the multiselected items
transfer to the listbox on the page of a tab control on
FormA. All is working but I am stuck at the transferring
from FormB to FormA.
Does anyone out there have any thoughts on this?
Thanks in advance for any assistance.
*** John
 
Hi John,

You will have to build a string from the first form's list box's
selected items. The A2002 help has an example on doing thins altho it
is for moving data, not copying it. Hopefully it will get you started.
---
The following example uses the Selected property to move selected
items in the lstSource list box to the lstDestination list box. The
lstDestination list box's RowSourceType property is set to Value List
and the control's RowSource property is constructed from all the
selected items in the lstSource control. The lstSource list box's
MultiSelect property is set to Extended. The CopySelected( ) procedure
is called from the cmdCopyItem command button.

Private Sub cmdCopyItem_Click()
CopySelected Me
End Sub

Public Sub CopySelected(ByRef frm As Form)

Dim ctlSource As Control
Dim ctlDest As Control
Dim strItems As String
Dim intCurrentRow As Integer

Set ctlSource = frm!lstSource
Set ctlDest = frm!lstDestination

For intCurrentRow = 0 To ctlSource.ListCount - 1
If ctlSource.Selected(intCurrentRow) Then
strItems = strItems & ctlSource.Column(0, _
intCurrentRow) & ";"
End If
Next intCurrentRow

' Reset destination control's RowSource property.
ctlDest.RowSource = ""
ctlDest.RowSource = strItems

Set ctlSource = Nothing
Set ctlDest = Nothing

End Sub
 
Back
Top