How do I get .ItemsSelected into an array

J

John

I have a multiselect Listbox.
And I am reading Access2002 Desktop Developers Handbook,
to try and figure out how to get "Listbox.ItemsSelected" into an Array.
The book shows me how to READ an array;
For lngCount = Lbound(alngValues) to Ubound(alngValues)
J=alngValues(lngCount)
Next lngCount

but I cant find out how to
write into the array to get started.

Can anyone please advise me?
Thank You!
 
D

Dirk Goldgar

John said:
I have a multiselect Listbox.
And I am reading Access2002 Desktop Developers Handbook,
to try and figure out how to get "Listbox.ItemsSelected" into an
Array. The book shows me how to READ an array;
For lngCount = Lbound(alngValues) to Ubound(alngValues)
J=alngValues(lngCount)
Next lngCount

but I cant find out how to
write into the array to get started.

Can anyone please advise me?
Thank You!

I have to ask, why? ItemsSelected is already an array; well, not
technically an array -- it's a collection -- but you can treat it as if
it were an array. For example,

With Me.lstHobbies
For lngCount = 0 To .ItemsSelected.Count - 1
Debug.Print lngCount, _
.ItemsSelected(lngCount), _
.ItemData(.ItemsSelected(lngCount))
Next lngCount
End With

If you really need to get the values out of the ItemsSelected collection
and into a separate array, you could do it easily enough: Do you want
to get the actual contents of the collection, which is a set of row
numbers, or do you want the data from the list box for those rows?
 
J

John

Hi Dirk,
Your response:
I have to ask, why? ItemsSelected is already an array; well, not
technically an array -- it's a collection -- but you can treat it as if
it were an array. For example,

With Me.lstHobbies
For lngCount = 0 To .ItemsSelected.Count - 1
Debug.Print lngCount, _
.ItemsSelected(lngCount), _
.ItemData(.ItemsSelected(lngCount))
Next lngCount
End With

If you really need to get the values out of the ItemsSelected collection
and into a separate array, you could do it easily enough: Do you want
to get the actual contents of the collection, which is a set of row
numbers, or do you want the data from the list box for those rows?

My Response:

What I want is the bound column of the selected rows so I can copy those
numbers into another table.
So I'll attempt to try & implement your code...
 
D

Dirk Goldgar

John said:
Hi Dirk,
Your response:


My Response:

What I want is the bound column of the selected rows so I can copy
those numbers into another table.
So I'll attempt to try & implement your code...

Fine. What you want then is

.ItemData(.ItemsSelected(lngCount))

Let me know if you have any further difficulty.
 
J

John

Hi Dirk,
Sorry, but there was more text in my previous post
that I must've accidentally deleted before posting.
I didn't mean to come across so abrupt.

I didn't realize that there are "Separate" Help files
for Access & VBA.
Also, I wanted to express my appreciation for your help!
Thank you, I think your code will work for me.
Much appreciated.
 
D

Dirk Goldgar

John said:
Hi Dirk,
Sorry, but there was more text in my previous post
that I must've accidentally deleted before posting.
I didn't mean to come across so abrupt.

It did feel a little odd, but this explains it.
I didn't realize that there are "Separate" Help files
for Access & VBA.

Annoying, isn't it? They did that starting with Access 2000, and we've
all been complaining ever since. Often, the best way to get help on any
keyword is to type it into the Immediate Window, then press F1 while the
text caret is in or touching the word.
Also, I wanted to express my appreciation for your help!
Thank you, I think your code will work for me.
Much appreciated.

You're welcome. As I said, let me know if you run into any more
problems.
 
Top