multi select list box

  • Thread starter Thread starter Andy G
  • Start date Start date
A

Andy G

I would like to have the multiselect feature turned on (simple or extended,
don't know the difference) and be able to loop through all of the selections
and on each one insert a record into a recordset.

Could someone please point me in the right direction.
Thanks.
 
The difference between Extended and Simple is how you make the multiple
selections. With Extended you use the standard Windows conventions of
holding down the Ctrl and/or Shift keys to make the multiple selections.
With Simple, each item you click on is remembered until you click on it
again to deselect it, so to select multiple items you would click on them
one at a time.

Looping through the selected items is exactly how you retrieve which items
have been selected. Remember, the value of a listbox comes from its Bound
Column. If the listbox has more than one column and you want the value from
a different column, you have to use the Column property to specify which
column to get the value from.

Example:
Dim varItem As Variant, rst As DAO.Recordset, db As DAO.Database
Set db = CurrentDb
Set rst = db.OpenRecordset("tblMyTable", dbOpenDynaset)
'Loop through the selected items
For Each varItem In Me.lstMyListbox.ItemsSelected
'Add each selected items to the table tblMyTable
With rst
.AddNew
!FieldName = Me.lstMyListBox.ItemData(varItem)
.Update
End With
Next
rst.Close
Set rst = Nothing
Set db = Nothing
 
Thank you so much Wayne.

Excellent to the point answer and very clear.

Thanks again!
Andy
 
Back
Top