multiselect list box

S

SAC

I want to be able to select several items in a list box, click a button and
insert some of the fields into an invoice items table.

How do I iterate through the selected items and grab the data for the
fields?

I was just testing using msgbox to see the data but I'm not getting it:

For Each intIndex In lstInventory.ItemsSelected
MsgBox ("Counter = " & lstInventory.ItemData(0))
MsgBox ("Dept = " & lstInventory.ItemData(1))
MsgBox ("Item ID = " & lstInventory.ItemData(2))
MsgBox ("Family = " & lstInventory.ItemData(3))
MsgBox ("Desc = " & lstInventory.ItemData(4))
MsgBox ("Total Inven = " & lstInventory.ItemData(5))

Next intIndex

What do I need to do?

Thanks.
 
K

Ken Snell \(MVP\)

Tell us what the setup is for the listbox. Are you wanting to use different
columns in the listbox for different fields in a table when writing data to
the table? Your code example is showing that you're using each row in the
listbox (the index number for the ItemData property) in each loop, which I
doubt is what you want.

Do you really need to redundantly store the "child" data from the listbox
(cannot you look up those data via queries based on the parent data?)?
 
S

SAC

Thanks, Ken.

I'm using the list box to list inventory items by category.

When selected I'd like each inventory item id to be inserted into an invoice
item table so it shows on the invoice items subform of the invoice main
form.

I guess I would need the desc and price to show also but not stored into the
table.

Hopes that enough info.

Thanks for your help.
 
S

SAC

SELECT tblInventory.Counter, tblInventory.Department, tblInventory.ItemID,
tblInventory.Family, tblInventory.Description, tblInventory.TotalInventory
FROM tblInventory
WHERE
(((tblInventory.Department)=[Forms]![frmLoadListSelect]![cboDepatment]))
ORDER BY tblInventory.Department, tblInventory.[Item ID];

The where clause refers to a combo box which limits the items to a category.

Thanks!!
 
K

Ken Snell \(MVP\)

To read the value of a specific column (which is a zero-based property) in a
multiselect listbox:

Dim varItemSel As Variant
For Each varItemSel In Me.ListBoxName.ItemsSelected
' read from second column of each selected item
MsgBox Me.ListBoxName.Column(1, varItemSel )
' read from third column of each selected item
MsgBox Me.ListBoxName.Column(2, varItemSel )
Next varItemSel

So, you can use variations on the above code to read the desired values from
one or more columns of each selected item.
--

Ken Snell
<MS ACCESS MVP>



SAC said:
SELECT tblInventory.Counter, tblInventory.Department, tblInventory.ItemID,
tblInventory.Family, tblInventory.Description, tblInventory.TotalInventory
FROM tblInventory
WHERE
(((tblInventory.Department)=[Forms]![frmLoadListSelect]![cboDepatment]))
ORDER BY tblInventory.Department, tblInventory.[Item ID];

The where clause refers to a combo box which limits the items to a
category.

Thanks!!


Ken Snell (MVP) said:
What is the RowSource query statement for the list box?
 
S

SAC

Excellent! Thanks!

Ken Snell (MVP) said:
To read the value of a specific column (which is a zero-based property) in
a multiselect listbox:

Dim varItemSel As Variant
For Each varItemSel In Me.ListBoxName.ItemsSelected
' read from second column of each selected item
MsgBox Me.ListBoxName.Column(1, varItemSel )
' read from third column of each selected item
MsgBox Me.ListBoxName.Column(2, varItemSel )
Next varItemSel

So, you can use variations on the above code to read the desired values
from one or more columns of each selected item.
--

Ken Snell
<MS ACCESS MVP>



SAC said:
SELECT tblInventory.Counter, tblInventory.Department,
tblInventory.ItemID, tblInventory.Family, tblInventory.Description,
tblInventory.TotalInventory
FROM tblInventory
WHERE
(((tblInventory.Department)=[Forms]![frmLoadListSelect]![cboDepatment]))
ORDER BY tblInventory.Department, tblInventory.[Item ID];

The where clause refers to a combo box which limits the items to a
category.

Thanks!!


Ken Snell (MVP) said:
What is the RowSource query statement for the list box?

--

Ken Snell
<MS ACCESS MVP>

Thanks, Ken.

I'm using the list box to list inventory items by category.

When selected I'd like each inventory item id to be inserted into an
invoice item table so it shows on the invoice items subform of the
invoice main form.

I guess I would need the desc and price to show also but not stored
into the table.

Hopes that enough info.

Thanks for your help.



Tell us what the setup is for the listbox. Are you wanting to use
different columns in the listbox for different fields in a table when
writing data to the table? Your code example is showing that you're
using each row in the listbox (the index number for the ItemData
property) in each loop, which I doubt is what you want.

Do you really need to redundantly store the "child" data from the
listbox (cannot you look up those data via queries based on the parent
data?)?

--

Ken Snell
<MS ACCESS MVP>


I want to be able to select several items in a list box, click a
button and insert some of the fields into an invoice items table.

How do I iterate through the selected items and grab the data for the
fields?

I was just testing using msgbox to see the data but I'm not getting
it:

For Each intIndex In lstInventory.ItemsSelected
MsgBox ("Counter = " & lstInventory.ItemData(0))
MsgBox ("Dept = " & lstInventory.ItemData(1))
MsgBox ("Item ID = " & lstInventory.ItemData(2))
MsgBox ("Family = " & lstInventory.ItemData(3))
MsgBox ("Desc = " & lstInventory.ItemData(4))
MsgBox ("Total Inven = " & lstInventory.ItemData(5))

Next intIndex

What do I need to do?

Thanks.
 

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