Populating 1 listbox from another listbox

Populating 1 listbox from another listbox

am 30.01.2008 19:09:27 von dkohel

I have 2 list boxes on my form. I am trying to populate listbox B
with the selection from listbox A. I have set multi-select in both
boxes to Extended...

The user will select the items from listbox A and click an Add button
that will then copy the items to listbox B. Then for each item in B,
I need to add them to a database. If there are 3 items in listbox B,
I need to add 3 line items to table B...

Any ideas?

Re: Populating 1 listbox from another listbox

am 30.01.2008 19:36:38 von manningfan

On Jan 30, 1:09=A0pm, "dko...@gmail.com" wrote:
> I have 2 list boxes on my form. =A0I am trying to populate listbox B
> with the selection from listbox A. =A0I have set multi-select in both
> boxes to Extended...
>
> The user will select the items from listbox A and click an Add button
> that will then copy the items to listbox B. =A0Then for each item in B,
> I need to add them to a database. =A0If there are 3 items in listbox B,
> I need to add 3 line items to table B...
>
> Any ideas?

I have an idea; learn how to use Google.

This is straight off Microsoft's website:

Example
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 =3D frm!lstSource
Set ctlDest =3D frm!lstDestination

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

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

Set ctlSource =3D Nothing
Set ctlDest =3D Nothing

End Sub