I have a form (frmLinks) that has a combo box (cboBuild) and a multiselect list box (lstTwo). The list box is actually populated from another list box on the form, that users can move items between. I want to be able to select an item from cboBuild, and click a button, and have a record created for every item in lstTwo (not just items selected, but everything in it) in tblLinks. If there are ten items in lstTwo, then I want ten records created in tblLinks; the records would have two fields, the ID obtained from cboBuild (which works properly), and the ID from the items in lstTwo (which doesn't work). I realize that the code I have below uses the ItemsSelected property; I'd like to get away from that, so the user doesn't have to transfer items from lstOne to lstTwo and then select everything in lstTwo if possible. Right now, when I click the button, I get records created in tblLinks, but there is no ID from the items in lstTwo. The bound column in both cboBuild and lstTwo is column 1, which is the ID.
Code: Select all
Dim DB As DAO.Database
Dim RST As DAO.Recordset
Set DB = CurrentDb
Set RST = DB.OpenRecordset("tblLinks")
For Each Item In lstTwo.ItemsSelected
RST.AddNew
RST!imageid = cboBuild
RST!updateid = lstTwo
RST.Update
Next
Set RST = Nothing
Set DB = Nothing
MsgBox "Updates linked successfully"