Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Select multiple names for List or ComboBox

Status
Not open for further replies.

netrusher

Technical User
Feb 13, 2005
952
US
I have a field on my form where Engineers Names are typed in the field. I would like to make this field a ComboBox or ListBox but I would still have the need to select multiple names. I have heard that you cannot do
this with a ComboBox. Is this true and if it is can anyone show me some code on how this can be done with a
Listbox?

I would like for the ListBox to have about 10 names and allow me to select any or all of the names from the
ListBox to be part of the field. The field would like like below if I selected 4 names.

Dwight Cross
Anthony Wasson
Rob Kirk
David Land

Thanks for any help!
 
This will do what you say

On my form I show a text box for the names to display. I use the list box to create the names. I lock the text box.

Code:
Private Sub List16_AfterUpdate()
  Dim varItem As Variant
  Dim strEngineer As String
  For Each varItem In Me.List16.ItemsSelected
    strEngineer = strEngineer & List16.ItemData(varItem) & vbCrLf
  Next varItem
    strEngineer = Trim(strEngineer)
    Me.engineer = strEngineer
End Sub

However this is a poor database design. Putting information into a field like this is not normalized. Normally this is done with a junction table (ie. "tblProjects_Engineers") that links many engineers to many projects.

You can use the above control to initially populate the text box, but you would have to write extra code to rehighlight the textbox with names already in the field.

A better design is to normalize the database and use a subform. In the subform you pick from a combo box the names you want and create a child record.
 
Thanks for the help! I do not think I explained myself good
enough before:
My bottom line is the only place I want to store the
names of the Engineers is on the Form. A copy of this form
is sent to those who need to see the form to do some work.
A email will be generated to the Engineers that are
selected fromt he ListBox and I guess I would have those
names appear in a TextBox.

I might have misspoken. The Engineers names are stored in a
EngNameTbl. That is where the ListBox will get the names.
Each form represents work to be accomplished and can be for
one engineer or multiple engineers. On the form itself I
need to be able to show each engineer the form has been
assigned to. Hope that helps and again, I am certainly
willing to change if it is needed. I am definitely open to
suggestions.
 
Hi

That is exactly as I thought you had it. I assume you have a table or Engineers assigne to a worktask, something like:

WorktaskId
EngineerId

In which case the link I posted above explains how to do what you are trying to accomplish

Regards

Ken Reay
Freelance Solutions Developer
Boldon Information Systems Ltd
Website needs upgrading, but for now - UK
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top