Why does it add two items?

S

Stapes

Hi

I have the following line of code:

ctrlListBox.AddItem Item:=strItem

However, where the value of strItem contains a comma, such as KOREA,
DEMOCRATIC PEOPLE'S REP, it comes out as two separate items, KOREA and
DEMOCRATIC PEOPLE'S REP.

Why is this? How can I prevent it?

Stapes
 
D

Dirk Goldgar

Stapes said:
Hi

I have the following line of code:

ctrlListBox.AddItem Item:=strItem

However, where the value of strItem contains a comma, such as KOREA,
DEMOCRATIC PEOPLE'S REP, it comes out as two separate items, KOREA and
DEMOCRATIC PEOPLE'S REP.

Why is this? How can I prevent it?


Because the list box uses the comma as a value-separator in its rowsource,
you must enclose the value to be added in quotes (single or double) when you
add it, if it contains (or may contain) a comma:

ctrlListBox.AddItem Item:=Chr(34) & strItem & Chr(34)
 
Top