AddItem method on ListBox

G

Guest

In Acces 2003:

I have the following issue. When adding items to a 3 column listbox using
the AddItem method and adding certain values Access fills less columns than
expected.

Example:

"Chair";"320,00";"0%" <----- goes fine!

"Chair;Blue";"320,00";"19%" <----- Results in "Chair;Blue" in the first
column and "320,00" in the second, the last column will be unfilled.

"Chair;Blue;Tall";"320,00";"20%" <----- Results in "Chair;Blue;Tall" in the
first column, the second and third columns remain empty.

In this case it seems like access first evaluates the number of semi-colons
(even quoted ones!) against the number of comumns in the listbox. Then it
discards the fourth semi-colon and everything found thereafter. It then
proceeds to fill the row with values but this time correctly ignores quoted
semi-colons, therefore coming up short on values to fill the entire row with.
 
D

Douglas J Steele

Can you not use a different delimiter for what's in the quoted parts?

--
Doug Steele, Microsoft Access MVP

(no e-mails, please!)


Dirk said:
In Acces 2003:

I have the following issue. When adding items to a 3 column listbox using
the AddItem method and adding certain values Access fills less columns than
expected.

Example:

"Chair";"320,00";"0%" <----- goes fine!

"Chair;Blue";"320,00";"19%" <----- Results in "Chair;Blue" in the first
column and "320,00" in the second, the last column will be unfilled.

"Chair;Blue;Tall";"320,00";"20%" <----- Results in "Chair;Blue;Tall" in the
first column, the second and third columns remain empty.

In this case it seems like access first evaluates the number of semi-colons
(even quoted ones!) against the number of comumns in the listbox. Then it
discards the fourth semi-colon and everything found thereafter. It then
proceeds to fill the row with values but this time correctly ignores quoted
semi-colons, therefore coming up short on values to fill the entire row
with.
 
G

Guest

The first item will be from a free text field. Therefore I have no control
over what "delimiter" will be used inside the quotes. Quotes I can escape by
doubling them up. The reason I quote all the values in the first place is to
be able to escape ";" and "," being interpreted as delimiters.

"Douglas J Steele" schreef:
 
J

John Spencer

I suspect that you have to use double quotes around your string values.

Me.Combobox.AddItem """Chair;Blue"" ;""320,00"";""19%"""
 
G

Guest

Unfortunately that does not work. Using double quotes around values makes
AddItem not add anything at all. I think this is because it evaluates the
first string it finds per delimiter. Since the first string is allways an
empty one, starting every item with double quotes, all items will be blank.

"John Spencer" schreef:
 
G

Guest

For now I will use a workaround: filter all uses of the semi-colon and
replace it with an empty string. I would however like to revisit this issue.
If anyone comes up with a solution or a reason AddItem behaves in such a
manner, please let me know.

"Dirk" schreef:
 
J

John Spencer

I got different results then blank, but I did get problems. If I shifted
the "internal" semi-colons to commas then the string seemed to be correctly
parsed. It appears that there is a bug in this code that gets confused when
the individual items contain the character that is being used to parse out
the items.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top