Temp store selected values of listbox

G

Guest

Hi,

My scenario:
I have tblProducts 1:M with tblProductDetails
tblProducts holds the name of the products while tblProductDetails hold
different rates for a particular product that is used on different crops that
we grow.
Say, a product called Bravo can have a different rate for Cabbages and a
different rate for Lettuces.
Often more than one product is applied in an application to crops
Therefore, I have a cbo or a list box that has products that will filter
another listbox that will contain the different rates of the selected product.

So again, goin thru the products that will be applied to crops and selecting
their appropriate rate which will be inserted to the tables.

How do i in vba temporarily hold the selected values of a mulitselect
listbox (rates of application of products) while the listbox is being
required for more values selection and once all wanted values are selected,
I would like to insert them into a table by a click on a cmdbtn.
I already have the cmdbtn that can insert values from a mutlitselect listbox
into table.

Hope I have made myself clear on this. I would appreicate any help. Thanks
in advance.
 
G

Guest

I would suggest using an array to hold the ItemsSelected in the list box.
Dim an array to match the number of items selected, then loop throught the
ItemsSelected collection and add each to the array.
 
G

Guest

Klatuu,
Thanks for the tip. However, I am a lil bit of a newbie to vba and all, it
would be so generous if you cound give me some air code or point me to some
vba resources website where I can find a similar example or sample.

Im stuck on this for a couple of days now.

Thanks
 
G

Guest

I will put something together for you. It is late in the day, my time, so I
will have to do it tomorrow.
 
G

Guest

Thanks Klatuu,
Its early in the day, my time but I can wait till tomorrow. Hear from you
soon.
Thanks,
 
G

Guest

My apologies for being so long getting back to you. It has been hectic here.
Here is the basic logic for transfering the selected items in a multi select
list box to an array.

Public Sub ListToArray()
Dim varItm As Variant
Dim intSelected As Integer
Dim intX As Integer

intSelected = Forms!frmupolabor!lstBillProdOffering.ItemsSelected.Count
ReDim aryItems(intSelected) As String

For Each varItm In Forms!frmupolabor!lstBillProdOffering.ItemsSelected
aryItems(intX) =
Forms!frmupolabor!lstBillProdOffering.ItemData(varItm)
intX = intX + 1
Next varItm

End Sub
 

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