A Microsoft Office (Excel, Word) forum. OfficeFrustration

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

Go Back   Home » OfficeFrustration forum » Microsoft Access » Using Forms
Site Map Home Register Authors List Search Today's Posts Mark Forums Read  

Selection from List Box to Text Box



 
 
Thread Tools Display Modes
  #1  
Old June 10th, 2009, 06:27 PM posted to microsoft.public.access.forms
Trini Gal
external usenet poster
 
Posts: 20
Default Selection from List Box to Text Box

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.
  #2  
Old June 10th, 2009, 07:13 PM posted to microsoft.public.access.forms
Douglas J. Steele[_3_]
external usenet poster
 
Posts: 3,143
Default Selection from List Box to Text Box

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.



  #3  
Old June 10th, 2009, 09:51 PM posted to microsoft.public.access.forms
Trini Gal
external usenet poster
 
Posts: 20
Default Selection from List Box to Text Box

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.




  #4  
Old June 10th, 2009, 10:51 PM posted to microsoft.public.access.forms
Douglas J. Steele[_3_]
external usenet poster
 
Posts: 3,143
Default Selection from List Box to Text Box

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.






  #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.






  #6  
Old June 11th, 2009, 03:09 PM posted to microsoft.public.access.forms
Douglas J. Steele[_3_]
external usenet poster
 
Posts: 3,143
Default Selection from List Box to Text Box

I think I've got code to do that in my March, 2006 "Access Answers" column
in Pinnacle Publication's "Smart Access". You can download the column (and
sample database) for free from
http://www.accessmvp.com/DJSteele/SmartAccess.html

If not, post back.

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


"Trini Gal" wrote in message
...
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.








  #7  
Old December 22nd, 2009, 07:50 PM posted to microsoft.public.access.forms
sebastico
external usenet poster
 
Posts: 74
Default Selection from List Box to Text Box

Douglas

Excellent example

"Douglas J. Steele" wrote:

I think I've got code to do that in my March, 2006 "Access Answers" column
in Pinnacle Publication's "Smart Access". You can download the column (and
sample database) for free from
http://www.accessmvp.com/DJSteele/SmartAccess.html

If not, post back.

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


"Trini Gal" wrote in message
...
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.









 




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Forum Jump


All times are GMT +1. The time now is 07:26 PM.


Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 OfficeFrustration.
The comments are property of their posters.