Select multiple items from a combo box

  • Thread starter Thread starter Rick
  • Start date Start date
R

Rick

I have a database with customers. One of the fields is
the 'source'. In some cases, a customer may have more
than one source. I recall seeing an example in Northwinds
or Solutions that allowed you to hold down the CTRL key
and click more than one item in a list and store it. Can
you help me find a good example of this? I'm assuming
that I would need to create a separate table for my
sources which allows more than one record per customer.
Storing the source in a field in my customer table would
not work with the above scenario.

A second related question, I would like the end-user to
see the sources in one field separated by commas. For
example:

Smith, Ralph Mailer, Houston, Renter
Smith, Sarah Phone, Mailer, Owner
Smith, Tom Mailer



any help would be appreciated.
 
Hi,
You can use a multi-select listbox for this.
In gerneral, you iterate through the ItemsSelected
collection, creating a record for each item.

So, let's assume you have a control on your form with the CustId
in it.

Dim varItem As Variant
Dim strSql As String
Dim db As Database

Set db = CurrentDb()

For Each varItem In Me.yourListBox.ItemsSelected
strSql = "Insert Into yourTable (CustId, otherField) Values(" & _
Me.CustId & ",'" & Me.yourListBox.ItemData(varItem) & "')"
db.Execute strSql
Next varItem

Set db = Nothing
 
Back
Top