Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Westi on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Obtaining multiple values from list box

Status
Not open for further replies.

addy

Technical User
May 18, 2001
743
GB
Hi

I would like to add a list box to my form and then have a button which when the user clicks it, will gather all the selections highlighted by the user in the list and turn them into a comma separated string.

Example, suppose my list contains the numbers 1 to 10, and the user selects 3 4 & 9 then the string would be

3, 4, 9

How do I go about this? I know I can use the ItemsSelected and ItemData functions to work through the list box and gather the data but how do I use this? Do I need to create an array and store all the value gathered in there beofre processing the string?

Thanks.
 
Have you done a search on "listbox" in the Access forums? This has been answered quite a few times. Here are two such answers from the Access Forms forum.

thread702-1254728
thread702-1256327

Search first. It will save you time.
 
How are ya addy . . .

To start you off try the following in the [blue]Click[/blue] event of the button:
Code:
[blue]   Dim LBx As ListBox, Build As String, idx
   
   Set LBx = Me![purple][b][i]ListboxName[/i][/b][/purple]
   
   For Each idx In LBx.ItemsSelected
      If Build <> "" Then
         Build = Build & "," & LBx.Column(0, idx)
      Else
         Build = LBx.Column(0, idx)
      End If
   Next
   
   Me![purple][b][i]TextboxName[/i][/b][/purple] = Build
   
   Set LBx = Nothing[/blue]
[blue]Your Thoughts? . . .[/blue]

Calvin.gif
See Ya! . . . . . .
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top