Populating text box using selections from multiselection list box


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

Advertisements

B

Beetle

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

Advertisements

K

KarenB

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.
 

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