View Single Post
  #5  
Old June 11th, 2009, 02:46 PM posted to microsoft.public.access.forms
Trini Gal
external usenet poster
 
Posts: 20
Default Selection from List Box to Text Box

Douglas,

Thank you so much for taking the time to explain to me the steps.

The code worked great. I only have one question. As I scan through my
records, the "spots" that were highlighted in the previous record stays
highlighted in the next one. Is there a way to unhighlight after I click on
my transfer button?

Thanks.

"Douglas J. Steele" wrote:

Somehow you need to know when the user has finished selecting items from the
list box, so you may want to consider having a command button for that. If
that's the route you take, you'd put that code in the Click event of that
command button. Once you've figured out strValues, just plug it into the
text box on your form that's bound to the field in the table.

List boxes have a collection named ItemsSelected associated with them. As
the name implies, the collection contains one entry for each selected row in
the list box. The code is loop through all of the items in that collection
(using a variable varSelected), and determining what the value is for each
row (using the ItemData property of the list box. It concatenates each value
into the variable strValues (adding a comma and space after each entry).
Once it's finished concatenating the details for all of the selected rows,
it removes the final comma and space from the end of the string.

--
Doug Steele, Microsoft Access MVP
http://I.Am/DougSteele
(no private e-mails, please)


"Trini Gal" wrote in message
...
Douglas,

Thanks for answering my post. Where would I put this code? I'm not sure
what the code is doing, can you explain a little for future reference
please?

Thanks.

"Douglas J. Steele" wrote:

You can't bind a multi-select list box, so you'll have to do this via
VBA.

Dim ctlLB As Control
Dim strValues As String
Dim varSelected As Variant

Set ctlLB = Me!NameOfListbox

strValues = vbNullString

If ctlLB.ItemsSelected.Count 0 Then
For Each varSelected in ctlLB.ItemsSelected
strValues = strValues & ctlLB.ItemData(varSelected) & ", "
Next varSelected
strValues = Left$(strValues, Len(strValues) - 2)
End If

strValues will now contain a comma-delimited list of all of the items
selected in the listbox.

--
Doug Steele, Microsoft Access MVP
http://I.Am/DougSteele
(no e-mails, please!)


"Trini Gal" wrote in message
news Hello,

I have a multi select list box, and I would like to have each selection
the
user selects to show up in a text box separated by commas. I have read
enough and I know that its "Evil" to store more than one piece of data
in
a
field. This textbox is a notes/memo field, and is only being used as
such.
I'm thinking that this would happen in the AfterUpdate Event of the
List
Box.

Does anyone have code that would help me out, or can someone point me
in
the
right direction?

Thanks.