Populating text box using selections from multiselection list box

  • Thread starter Thread starter KarenB
  • Start date Start date
K

KarenB

I have a form with a multiselection list box showing account names and also
multiple command buttons which open up various reports using the account
names selected as filters. That is working fine, but what I can't figure out
is how to populate a text box with the account names selected from the list
box so that the user can see all of the account names chosen for the reports
being run. The list box contains 857 entries, so I can't make it big enough
on the form to see all the selections. Any ideas? I am using Access 2007.
 
You can use code like the following in the Click event of the
list box to display the names in an unbound text box;

Private Sub lstYourListBox_Click()

Dim strDisplayNames As String
Dim varItem As Variant

strDisplayNames = ""

For Each varItem In Me!lstYourListBox.ItemsSelected
strDisplayNames = strDisplayNames & _
Me!lstYourListBox.ItemData(varItem) & ", "
Next varItem

If Len(strDisplayNames) > 0 Then
strDisplayNames = _
Left(strDisplayNames, Len(strDisplayNames) - 2)
End If

Me!txtYourTextBox = strDisplayNames

End Sub


I have added continuation characters to try and correct for the
newsgroup line wrap.
 
Worked like a charm - thank you!

Beetle said:
You can use code like the following in the Click event of the
list box to display the names in an unbound text box;

Private Sub lstYourListBox_Click()

Dim strDisplayNames As String
Dim varItem As Variant

strDisplayNames = ""

For Each varItem In Me!lstYourListBox.ItemsSelected
strDisplayNames = strDisplayNames & _
Me!lstYourListBox.ItemData(varItem) & ", "
Next varItem

If Len(strDisplayNames) > 0 Then
strDisplayNames = _
Left(strDisplayNames, Len(strDisplayNames) - 2)
End If

Me!txtYourTextBox = strDisplayNames

End Sub


I have added continuation characters to try and correct for the
newsgroup line wrap.
 
Back
Top