Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Multiple line list of values for a Combobox.

Status
Not open for further replies.

ll4u76

Technical User
Apr 12, 2012
4
US
I have a long list of values to add to my combobox. I had to break the list down into a couple of lines. I have typed the code a couple of different ways but keep getting Complie errors. Here are some examples:

Me.ComboBox1.List=Split("item 1|item 2|item 3|item 4|item 5|" & _
item 6|item 7|item 8|item 9|item 10|item 11|item 12|item 13|" & _
"item 14|item 15|item 16|item 17|item 18|item 19|item 20|" & _
"item 21|item 22|item 23|item 24|item 25|item 26|item 27|" & _
"item 28|item 29|item 30", "|")


Me.ComboBox1.List=Split("item 1|item 2|item 3|item 4|item 5|) & _
(item 6|item 7|item 8|item 9|item 10|item 11|item 12|item 13|) & _
(item 14|item 15|item 16|item 17|item 18|item 19|item 20|item) & _
(21|item 22|item 23|item 24|item 25|item 26|item 27|item 28|) & _
(item 29|item 30", "|")

Please assist in typing this code to read all of the lines of data items for the combobox without getting an error.
 
I have no problem with the first option, after adding missing quotation mark at the beginning of the second line.

Personally in such cases I prefer to build the string first:
[tt]strCB = "item 1|item 2|item 3|item 4|item 5|" & _
"item 6|item 7|item 8|item 9|item 10|item 11|item 12|item 13|" & _
"item 14|item 15|item 16|item 17|item 18|item 19|item 20|" & _
"item 21|item 22|item 23|item 24|item 25|item 26|item 27|" & _
"item 28|item 29|item 30"
Me.ComboBox1.List = Split(strCB, "|")[/tt]


combo
 
This has gotten rid of the errors. Now my combobox4 does not pick up the data items.

I have 7 comboboxes listed as:

Private Sub Document_Open()
Me.ComboBox1.List = Split("Select")
Me.ComboBox2.List = Split("Select")
Me.ComboBox3.List = Split("Select")
strCB = "Select|itme 1|item 2|item 3" & _
"item 4|item 5|item 6"
Me.ComboBox4.List = Split(srtCB, "|")
Me.ComboBox5.List = Split("Select")
Me.ComboBox6.List = Split("Select")
Me.ComboBox7.List = Split("Select")
End Sub
 

[tt]
Private Sub Document_Open()
Me.ComboBox1.List = Split("Select")
Me.ComboBox2.List = Split("Select")
Me.ComboBox3.List = Split("Select")
strCB = "[red]Select|[/red]item 1|item 2|item 3[red]|[/red]" & _
"item 4|item 5|item 6"
Me.ComboBox4.List = Split(srtCB, "|")
Me.ComboBox5.List = Split("Select")
Me.ComboBox6.List = Split("Select")
Me.ComboBox7.List = Split("Select")
End Sub
[/tt]

Have fun.

---- Andy
 
I would also suggest naming your combo boxes (if possible) as it makes it easier to know which one is which.

If at first you don't succeed, then sky diving wasn't meant for you!
 
If you need to have "Select" initially displayed by the combobox, set its value:
[tt]Me.ComboBox4.List = Split(strCB, "|")
Me.ComboBox4.[!]Value[/!] = "Select"
Me.ComboBox5.[!]Value[/!] = "Select"[/tt]
NB., again, check spelling (strCB vs. srtCB).

combo
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top