Select items in multiple column listbox and adding it to multiple fields in a table.

  • Thread starter Thread starter madisonlynn
  • Start date Start date
M

madisonlynn

I have two listboxes. So far the first 3 columns listbox is capturing data
from a table and populating it into the second listbox. I would like to
know how I can append the selected 3 columns into a table with its
corresponding 3 fields.

Thanks for your help,
Madison Lynn
 
Here is some code that you can adapt to your situation - basically it simply
opens a recordset on the table to which you are adding records. Then loops
through the selected items, adding a new record for each selected item in
the listbox. In my example, the listbox had only two columns, PersonNbr and
ClassID.

Private Sub cmdAddOne_Click()
Dim varItem As Variant
Dim rst As DAO.Recordset
Dim db As DAO.Database
Set db = CurrentDb()
Set rst = db.OpenRecordset("Select * from tblPersonClasses where
PersonNbr=-1")
For Each varItem In Me.lstAvailable.ItemsSelected
With rst
.AddNew
.Fields("PersonNbr") = Me.PersonNbr
.Fields("Classid") = Me.lstAvailable.ItemData(varItem)
.Update
End With
Next varItem
rst.Close
Set rst = Nothing
Set db = Nothing
Me.lstAvailable.Requery
Me.lstSelected.Requery
End Sub
 
Back
Top