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 strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Multiselect List Box Results to TextBox???

Status
Not open for further replies.

AccessDevJunior

Programmer
Apr 14, 2004
81
GB
hya,

I have a problem with a multiselect listbox. I would like all the selected rows of the list box to appear within an unbound textbox but only one result shows at a time. I have th following code on the after update of the list box. If anyone knows and could tell me how to get around this it would be a great help?

Dim ctrl As ListBox
Dim varItems As Variant

Set ctrl = Me!ListUsers

For Each varItems In ctrl.ItemsSelected
Me.Text1 = ctrl.ItemData(varItems) & ", "

Next varItems
 
Try a bit of concatenation;-)

[tt]Me.Text1 = Me.Text1 & ctrl.ItemData(varItems) & ", "[/tt]

For better performance, perhaps assign to a string variable first, then to the text control - but what's the purpose of this? If you're looking for passing for instance a wherecondition when opening a form or report, see for instance thread702-787778

Roy-Vidar
 
thanks RoyVidar that works but it seems to copy the last value again?

I dont need to populate a text box i was just using a text box to text the code. I want the list box to be used to select numerous users to send an email to.

 
Oh - the after update, then only

[tt]Me.Text1 = Me.Text1 & ctrl & ", "[/tt]

But this approach is a bit dangerous, what do you do if the user selects the same occurance more than once?

I'd recommend using a button, then after the selection is performed, the approach in the thread I referenced to build the criterion for you e-mail list.

Roy-Vidar
 
thankyou again for the fast response,

there will only be a few users accessing this part of the database so when training takes place i will enphasize this point.

the new code you have just posted, when i select a user a comma just appears everytime -without their email address?
 
Yes, forgot to say, with this approach, you are not using Multiselect, so set multiselect to None.

Roy-Vidar
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top