-
I am trying to take the contents of the ListBox and copy them into a variable ready to be pumped into a DB.
However I can't read in the value of the ListBox???
Has anyone come across this befor..........What should the correct sytax if the statement be??
Any remarks would be cool
Cheers
-
Dim listboxdata() As String
'Store the data from the list box
For x = 0 To List1.ListCount - 1
ReDim Preserve listboxdata(x + 1)
listboxdata(x + 1) = List1.List(x)
Next x
For x = 1 To UBound(listboxdata)
listboxdata(x) add to database....
Next x
-
<?>
Code:
Private Sub Command1_Click()
Dim i As Integer
For i = 1 To 10
List1.AddItem i
Next i
Dim myArr()
For i = 0 To List1.ListCount - 1
List1.ListIndex = i
ReDim Preserve myArr(i)
myArr(i) = List1.Text
Next i
End Sub
'now you have the contents loaded into an array and you
'can populate your file with the information.
'open the db and what not
'to add the rec use a loop
For i = LBound(myArr) To UBound(myArr)
Data1.addnew
Data1.Recordset!yourfield = myArr(i)
Data1.Update
Next i
'close or whatever.