Creating array from listbox values

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hello,

I need to create an array from value in an listbox. So far I have the
following code:

_______
strSQL = "SELECT TblCallSLA.SLA_Number " & _
"FROM TblCallSLA " & _
"WHERE TblCallSLA.Practice='DDS'"

Form_Form1!lstSLA_Numbers.RowSource = strSQL

For lSelItem = 0 To Form_Form1!lstSLA_Numbers.ListCount - 1
Form_Form1!lstSLA_Numbers.Selected(lSelItem) = True
MyArray = MyArray & Form_Form1!lstSLA_Numbers.Value & ", "
Next
MyArray = Array(Left(MyArray, Len(MyArray) - 2))

For Each varArray In MyArray
etc.....
_________

But something goes wrong. 'varArray' holds the entire string instead of
individual values of the array. What am I doing wrong or is there a simpler
way to create an array from listbox values?

Thanks

René
 
Dim strValues() As String

ReDim strValues(Form_Form1!lstSLA_Numbers.ListCount - 1)

For lSelItem = 0 To Form_Form1!lstSLA_Numbers.ListCount - 1
Form_Form1!lstSLA_Numbers.Selected(lSelItem) = True
strValues(ISelItem) = Form_Form1!lstSLA_Numbers.Column(1,
lSelItem)
Next lSelItem

The above assumes that you want the value from the 2nd column in the list
box (column numbering starts at 0)

(BTW, you can't use For Each with an array, at least not in VBA)
 
Back
Top