Adding Items To a Multi-Column Listbox

B

bwion

Hey All,

I seem to be having trouble with something that seems pretty routine. I have
one listbox (multi-column) that has Multi-Select enabled and it is based off
a query. I want to be able to select items from that listbox and then click a
command button and it transfers the items that I selected from that listbox
to another listbox (multi-column as well). The listbox columns will contain
the same information too. Here is what I am trying in the command button's
click event procedure with no luck:

Dim i As Integer

If Me.lstCSRItems.ListIndex = -1 Then Exit Sub

For i = Me.lstCSRItems.ListCount - 1 To 0 Step -1

If Me.lstCSRItems.Selected(i) = True Then

Me.lstSRItems.AddItem
Me.lstCSRItems.Column(0,i);Me.lstCSRItems.Column(1,i);Me.lstCSRItems.Column(2,i);Me.lstCSRItems.Column(3,i);Me.lstCSRItems.Column(4,i);Me.lstCSRItems.Column(5,i);Me.lstCSRItems.Column(6,i)

End If

Next i

The AddItem method only seems to want to work with hardcoded strings. Any
thoughts on how I can add items to a multi-column listbox? Thanks in advanced
for the help.

Ben Wion
 
J

Jeff Boyce

Ben

You did say "any thoughts..." <g>

It sounds like you are creating a value list in the second listbox, based on
choices in the first. Wouldn't that mean that every time you picked
different items in the first, you'd end up with different items in the
second? How are you using the information in the second? Is that supposed
to be part of a record somewhere?

A common approach using paired listboxes is to use that button click to copy
the IDs of the items selected in listbox1 into a table, then requery the
listbox2, which just happens to be based on a query against that table that
just got the items added to it!

If you'll describe a bit more why you are doing this (i.e., what will you do
with the second listbox information), folks may be able to offer more
specific suggestions.

Regards

Jeff Boyce
Microsoft Office/Access MVP
 
B

bwion

Hey All,

I figured it out. I was using the second listbox as a value list. After the
user put items in that second listbox and clicked a command button labeled
"Save Items" it invoked some DAO code to add those Items to a different
table. Here is the code (in a command buttons click event procedure) to
transfer the items from list1 to list2 that I used that worked:

Dim i As Integer

If Me.lstCSRItems.ListIndex = -1 Then Exit Sub

For i = 0 To Me.lstCSRItems.ListCount - 1

If Me.lstCSRItems.Selected(i) = True Then

Me.lstSRItems.AddItem Me.lstCSRItems.Column(0, i) & ";" &
Me.lstCSRItems.Column(1, i) & ";" & Me.lstCSRItems.Column(2, i) & ";" &
Me.lstCSRItems.Column(3, i) & ";" & Me.lstCSRItems.Column(4, i) & ";" &
Me.lstCSRItems.Column(5, i) & ";" & Me.lstCSRItems.Column(6, i)

End If

Next i

Thanks,
Ben Wion
 

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