I have a form that uses a lisbox selection to populate a textbox. The first listbox works fine. I have added another listbox and textbox to do the same with employee name, however the code does not allow me to populate the textbox with more than one name at a time. It replaces the name I selected first with the next one I select. Here is the code for both of them. The one that works fine is the lstcompanies. The one that doesn't is lstemployees. I hope someone can help.
Private Sub lstCompanies_AfterUpdate()
Dim varItem As Variant
Dim strList As String
With lstCompanies
If .MultiSelect = 0 Then
txtSelected = .Value
Else
For Each varItem In .ItemsSelected
strList = strList & .Column(0, varItem) & vbCrLf
Next varItem
txtSelected = strList
End If
End With
End Sub
Private Sub lstemployees_AfterUpdate()
Dim varItem2 As Variant
Dim strList2 As String
With lstemployees
If .MultiSelect = 0 Then
Txtselectedemploy = .Value
Else
For Each varItem2 In .ItemsSelected
strList2 = strList2 & .Column(0, varItem2) & vbCrLf
Next varItem2
Txtselectedemploy = strList2
End If
End With
End Sub
Private Sub lstCompanies_AfterUpdate()
Dim varItem As Variant
Dim strList As String
With lstCompanies
If .MultiSelect = 0 Then
txtSelected = .Value
Else
For Each varItem In .ItemsSelected
strList = strList & .Column(0, varItem) & vbCrLf
Next varItem
txtSelected = strList
End If
End With
End Sub
Private Sub lstemployees_AfterUpdate()
Dim varItem2 As Variant
Dim strList2 As String
With lstemployees
If .MultiSelect = 0 Then
Txtselectedemploy = .Value
Else
For Each varItem2 In .ItemsSelected
strList2 = strList2 & .Column(0, varItem2) & vbCrLf
Next varItem2
Txtselectedemploy = strList2
End If
End With
End Sub