Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Multi-Select list box: saving/appending data to a table

17 views
Skip to first unread message

gor...@hotmail.com

unread,
Dec 15, 2009, 2:15:49 PM12/15/09
to
I am trying to append records to a linking table which contains 3 ID
numbers (fldCustomerID / fldSalesAreaID / fldProductID using a simple
form which contains 2 combo boxes (for CustomerID and SalesAreaID) and
a multi select list box for ProductID.

The user selects a customer, a sales area and then between 1 and 3
products. On the press of a form button, I want to append to the link
table between 1 and 3 records depending upon the number of products
selected.

Here is the code I am using;
Dim ctlList As Control, varItem As Variant
Dim rst As Recordset, db As Database
Set db = CurrentDb
Set rst = db.OpenRecordset("tblCustomerAreaProductLinks")
Set ctlList = Forms!frmAssignEnquiries!lstProducts
' Enumerate through selected items.
For Each varItem In Me.lstProducts.ItemsSelected
rst.AddNew
rst!fldProductID = ctlList.ItemData(varItem)
rst!fldCustomerID = Me!cboSelectCustomer
rst!fldSalesAreaID = Me!cboSelectArea
rst.Update
Next varItem
rst.Close

This doesn't work and the database just seems to go into an
interminable loop. I am a fairly experienced novice at code (!!!) but
I am stuck. Am I on the right track here or is there a simpler way to
achieve my objective?

Gordon

0 new messages