Click here to Skip to main content
15,891,782 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have a database with a field called "Varernumrer" (Productnumbers). In this field i have written several numbers, seperated by , (comma). I now want to load these numbers into a listbox.

My code so far:
VB
Private Sub CommandButton2_Click()
   With rsFaktura
      UserForm1.ListBox1.AddItem !Varenumrer
   End With
End Sub


But that just gets the entire text and puts it in the first line of the listbox.

I use MS Office 2007 programs.

Hope anyone can help me.
Posted

You can populate a ListBox from a Range of cells on a scratch worksheet.

The way you're doing it now, you would have to supply code to parse that string, getting each value out of it and adding them, one-by-one to the ListBox.
 
Share this answer
 
I have found the solution myself.

the code is:

VB
Lines = Split(rsFaktura.Fields("Varenumrer"), ",")
num_rows = UBound(Lines)
Do While I <= num_rows
    Line = Split(Lines(I), ",")
    Line1 = Line(0)
    ListBox1.AddItem (Line1)
    Ark1.Cells(11, I + 15) = Line
    I = I + 1
Loop
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900