By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
435,208 Members | 1,072 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 435,208 IT Pros & Developers. It's quick & easy.

Populating 1 listbox from another listbox

P: n/a
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?
Jan 30 '08 #1
Share this Question
Share on Google+
1 Reply


P: n/a
On Jan 30, 1:09*pm, "dko...@gmail.com" <dko...@gmail.comwrote:
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?
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 = 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
Jan 30 '08 #2

This discussion thread is closed

Replies have been disabled for this discussion.