When adding string with comma in it to listbox it gets truncated

SLO2000

New member
Local time
Today, 00:43
Joined
Feb 9, 2010
Messages
3
Pulling my hair out on this one. I have a string value which has commas in it. It is an SQL statement. All I am trying to do is add the string to a single column listbox. When I do it it always parses my string at the first comma. I have searched all over the web, can't believe no one else has had this problem. My background is Excel VBA, never had this problem.

:eek:

Example
strString = "Select dog,cat, and cow from tblAnimals"

lbTest.AddItem strString

The listbox result is the following
Select dog

I want the listbox to show entire string.
Select dog,cat, and cow from tblAnimals
 
It can be a pain right? :) This is what you need:

Code:
strString = """Select dog,cat, and cow from tblAnimals"""
Notice, the text is wrapped in extra quotes, i.e. a quote enclosed in two quotes on both ends of the string. I hope that helps
 
Gracious. I have deep background in Excel VBA. Form objects seem to have some idiosynchroncies I have to learn to work with.
 
A much simpler solution is to change the delimiter to a semi-colon instead of a comma

Value List
"- Select Dog, Cat or Fish from list - ";"Dog";"Cat";"Fish"

David
 
The problem was that I needed the comma. It is a status monitor box that displays SQL statements as they execute. I didn't realize also that you can add "ActiveX" versions of the form objects to the form. These react very similiar to the Excel VBA environment objects. Moving foward will probably just use those object versions instead of the default Access one.
 
To use the existing Access listbox, the preferred on- simply perform a test on the string you are about to add to see if it contains a comma.

Code:
If Instr(strString,",") > 0 Then
   strString = """" & strstring & """"
End If

Me.ListBox.AddItem StrString

David
 

Users who are viewing this thread

Back
Top Bottom