Results 1 to 5 of 5
  1. #1
    Join Date
    May 2004
    Posts
    90

    Unanswered: Getting list box values to text string

    I have a list box that gets its data from a query. I was just wondering what the code was to get the items from the list box and to a text string so that I can display them across the screen (the list box has state abriviations)

    Ex.

    List box has this:

    States: AR
    MO
    KS
    etc..

    I want to convert to a text string and put result in a text box so that it
    looks like this: States: AR MO KS etc...

    What's the code to do this? Thanks

  2. #2
    Join Date
    Mar 2003
    Location
    The Bottom of The Barrel
    Posts
    6,102
    Provided Answers: 1
    How comfy are you with vba?

    You'll need to iterate through each row of the listbox and concatenate the values into a string.
    oh yeah... documentation... I have heard of that.

    *** What Do You Want In The MS Access Forum? ***

  3. #3
    Join Date
    Dec 2003
    Posts
    268

    Try This

    dim i as integer
    dim str as string
    With listbox
    for i = 0 to .columncount
    str = .column(i) & str
    next i

    msgbox str

  4. #4
    Join Date
    Mar 2003
    Location
    The Bottom of The Barrel
    Posts
    6,102
    Provided Answers: 1
    Quote Originally Posted by mjweyland
    dim i as integer
    dim str as string
    With listbox
    for i = 0 to .columncount
    str = .column(i) & str
    next i

    msgbox str
    Cheater



    If you're going to give it away, might as well tweak it up a bit....

    Code:
    dim i as integer
    dim str as string
    With listbox
       for i = 0 to .listcount
          str = .column(0, i) & str
       next i
    Wend
    
    msgbox str
    Last edited by Teddy; 06-17-04 at 17:57.
    oh yeah... documentation... I have heard of that.

    *** What Do You Want In The MS Access Forum? ***

  5. #5
    Join Date
    May 2004
    Posts
    90
    Thanks that worked

Posting Permissions

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