multiple listbox, selected items in array

key

Registered User.
Local time
Today, 03:36
Joined
Jun 19, 2002
Messages
45
Hi all,

how I can save the selected items from a multiple listbox in an array?
Do you have any examples for me?

I really appreciate it,

Key
 
It works, but not perfect...

O.K. This code works BUT if I use the shift and chose e.g. the 1st and 3rd items, I got the message 'subscript out of range'?

Does anyone knows why?


For Each k In Me![List0].ItemsSelected
countselected = countselected + 1
Next k

ReDim myarray(0 To countselected - 1) As Long

myarray(i) = Me![List0].ItemData(i)

Next i
 
Your code is not complete but it would seem that your i happens to take a value superior to the upper bound of your array (countselected)
 
I'm not sure your code is correct anyway. It looks as if it will give you the first items in your listbox to the number of items selected.

to illustrate

a
b(selected)
c
d(selected)
e

your code would return a and b (if you had selected three items it would return a,b,c)

You need to have the code tell you which items where selected.

try this instead:

Dim count As Long
count = [List0].ItemsSelected.count - 1
ReDim myarray(0 To count) As String

With [List0]
For x = 0 To count
myarray(x) = .ItemData(.ItemsSelected(x))
Next x
End With

For y = 0 To count
Debug.Print myarray(y)
Next y


If my thinking is incorrect feel free to let me know.
 

Users who are viewing this thread

Back
Top Bottom