Results 1 to 4 of 4

Thread: more listbox problems, additem not working right with various characters

  1. #1

    Thread Starter
    Frenzied Member wengang's Avatar
    Join Date
    Mar 2000
    Location
    Beijing, China
    Posts
    1,602

    more listbox problems, additem not working right with various characters

    Hi all.
    I have an Access form with a listbox, value list not bound, programmatically populated.

    Several characters are causing problems.

    If the Item contains a comma, it truncates after the comma (a single-column listbox)
    If it has an apostrophe, same thing, but before the apostrophe.

    I tried enclosing the Item in quotes, but then it started putting single quotes around the list item. Also, when the Item contained quotation marks, it did not display them properly, and in some cases, also truncated at the quotation mark.
    Help?

    Code is simple:

    lboResults.AddItem sLine 'a string of text
    also tried
    lboResults.AddItem chr(34) & sLine & chr(34)


    I'd rather not start the business of replacing characters with lookalikes if there is a way to get this working correctly.
    Wen Gang, Programmer
    VB6, QB, HTML, ASP, VBScript, Visual C++, Java

  2. #2
    PowerPoster
    Join Date
    Dec 2004
    Posts
    25,618

    Re: more listbox problems, additem not working right with various characters

    i tested with a userform listbox and for me those characters are not a problem, i assume your form is a access data form, rather than a userform, so there is probably some differences

    i am not sure about commas, but possibly the apostrophe should be escaped, worth a try any way
    i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case.
    Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next

    dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part

    come back and mark your original post as resolved if your problem is fixed
    pete

  3. #3
    Don't Panic! Ecniv's Avatar
    Join Date
    Nov 2000
    Location
    Amsterdam...
    Posts
    5,343

    Re: more listbox problems, additem not working right with various characters

    single quote you could replace ' with ยด (top left of the keyboard).
    If it is an access form in an access db, you dont normally use it like that with the additem. Userform in excel works more like vb, access however is a little more trickier.

    If you dont want to bind your table to the list (good idea not to) then the one route I have used is via a class object that deals with the calls the access form makes to draw and refresh. Bonus is that you can store in an array and display arrays as well as tables on the form. The pain in the butt part is setting it all up.

    ms reference some uh light reading i used as a reference

    BOFH Now, BOFH Past, Information on duplicates

    Feeling like a fly on the inside of a closed window (Thunk!)
    If I post a lot, it is because I am bored at work! ;D Or stuck...
    * Anything I post can be only my opinion. Advice etc is up to you to persue...

  4. #4

    Thread Starter
    Frenzied Member wengang's Avatar
    Join Date
    Mar 2000
    Location
    Beijing, China
    Posts
    1,602

    Re: more listbox problems, additem not working right with various characters

    Thanks for the replies, guys.
    I figured it out.
    The apostrophe was a red herring. I found a type in my code that was causing problems with apostrophe.
    As for comma and quotation, the comma is a delimiter so it requires quotations around the item to add.
    This causes problems for actual quotation marks, so they have to be accounted for as well:

    strValue = replace(strValue,chr(34),chr(34) & chr(34))
    Listbox1.AddItem chr(34) & strValue & chr(34)

    This eliminated all problems, and yes this was an Access form.
    Wen Gang, Programmer
    VB6, QB, HTML, ASP, VBScript, Visual C++, Java

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width