Multi Select List Box to Text Box (put each item on separate line)

G

Guest

Maybe I'm just overlooking the obvious, but is there a way to format the text
in a text box once I've selected it with the following code. (I am putting
the names of employees in a text box to show which employees were selected
for a particular record. The names are appearing in a straight line and
separated by a comma, I would each name to have its own line in the text box.
)

Dim varItem As Variant
Dim strList As String

With Me.Employee
If .MultiSelect = 0 Then
Me.Employee = .Value
Else

For Each varItem In .ItemsSelected
strList = strList & .Column(0, varItem) & ","
Next varItem
If strList <> "" Then
strList = Left$(strList, Len(strList) - 1)
End If
Me.Employee = strList
End If

End With

Also, is there a way to "unhighlight" the multi select text box for the
next record (so nothing is highlighted for the next record). I am using a
single form view. Thank you.
 
A

AccessVandal via AccessMonster.com

Hi Michelle,

Just add the line as below.
Michelle wrote:

For Each varItem In .ItemsSelected
strList = strList & .Column(0, varItem) & ","
.Selected(varItem) = False 'unselect listbox
Next varItem
 
G

Guest

Thanks AccessVandal, that did clear out my selections! Do you know how I
would format the text in the text box once I've selected. (I am putting the
names of employees in a text box to show which employees were selected for a
particular record. The names are appearing in a straight line and
separated by a comma, I would each name to have its own line in the text
box).

Right now my entries are appearing like this in the textbox:

Ex: Adams, Micheal,Adkins, Darla K,Albright, Gayla J

I would like them to appear like this:

Adams, Micheal
Adkins, Darla K
Albright, Gayla

Thanks for your help.
 
D

Douglas J. Steele

For Each varItem In .ItemsSelected
strList = strList & .Column(0, varItem) & vbCrLf
.Selected(varItem) = False 'unselect listbox
Next varItem
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top