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 TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Multiple selections in a list or combo box 2

Status
Not open for further replies.

zay99

Technical User
Apr 2, 2001
2
US
I need to create a list box or a combo box that allows me to select multiple items to record in a table. The list boxes that I have ceated do not allow that feature and the closest thing I have found in the samples is a dialog box that allows multiple selections to open multiple forms.
 
The listbox would seem the way to go and does support multi-select. The property that controls the selection behavior is the 'MultiSelect' property of the control.

Gary
gwinn7

 
Thank you gwin7. I know that but thta only allows me to select multiple. It does not allow the selections to be recorded after being selected. I also want to see that the selection was completed and when I go back or if I query the table I want to see the results of the selection. The list box I have created does not record the selections.
 
Oh I see now! Interesting!

OK. Well, the first possible solution that runs through my head is to serialize the selections into a string. Then, store that string in a Text field in the table. Example:

ID ---- NAME
1 Shoes <--- Selected
2 Socks
3 Shirt <--- Selected
4 Jacket

String containing selected items = &quot;1,3&quot;

As you can see you will need to decide on a delimiter so you can parse the selections with a function as well as building the string based on the selections to store the string in the field.

Somebody else might have a better solution, but the one I am suggesting maintains flexibility to create more selection options in your lookup table.

Gary
gwinn7

 
Do a keyword search there have been several posts describing ways to do this in the past couple of months.
 
This was code given to me on this site for a similar situation. I put this code behind a command button. I also had a macro run that used a query to update a flag in my data table to true where the data field=tempfield. Then I had a form that displayed the records whose flag was set to True. Don't know if it will help you......good luck!

Private Sub cbtnGo_Click()

Dim db As Database
Dim rs As Recordset
Dim varItem As Variant

Set db = CurrentDb

DoCmd.SetWarnings False
DoCmd.RunSQL &quot;Delete * from tempTable&quot;
DoCmd.SetWarnings True

Set rs = db.OpenRecordset(&quot;tempTable&quot;)

With rs
For Each varItem In List0.ItemsSelected
rs.AddNew
!tempField = List0.ItemData(varItem)
rs.Update
Next varItem
End With

rs.close: Set rs = Nothing
db.close: Set db = Nothing
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top