I, I'm learning how to add records to a table from different types of controls.
I'm having the following issue with ListBox. For one list box, let's say it contains 5 choices. then there are two text boxes on the same form.
The following code adds table entries for every selection made in the ListBox1 (Multi Select: Simple) and attaches entries from other cotrols for each ListBox1 selection.
Code:
Set rs = db.OpenRecordset("tblOut", dbOpenDynaset, dbAppendOnly)
For Each varItem1 In Me.Frm1LstBox1.ItemsSelected
rs.AddNew
rs!something1 = Me.Frm1TxtBox1
rs!something2 = Me.Frm1TxtBox2
rs!country = Me.Frm1LstBox1.Column(0, varItem1)
rs!color = Me.Frm1LstBox2.Column(0, varItem2) 'This code will add only first selection from list to the table
rs!plant = Me.Frm1LstBox3.Column(0, varItem3) 'This code will add only first selection from list to the table
rs.Update
Next varItem1
How do I efficiently nest let's say 3 ListBoxes so that entries in the table are created for every possible combination of choices from each ListBox?
Code:
Set rs = db.OpenRecordset("tblOut", dbOpenDynaset, dbAppendOnly)
For Each varItem1 In Me.Frm1LstBox1.ItemsSelected
For Each varItem2 In Me.Frm1LstBox1.ItemsSelected 'I know this won't work, it's just for ilustration
For Each varItem3 In Me.Frm1LstBox1.ItemsSelected 'I know this won't work, it's just for ilustration
rs.AddNew
rs!something1 = Me.Frm1TxtBox1
rs!something2 = Me.Frm1TxtBox2
rs!country = Me.Frm1LstBox1.Column(0, varItem1)
rs!color = Me.Frm1LstBox2.Column(0, varItem2)
rs!plant = Me.Frm1LstBox3.Column(0, varItem3)
rs.Update
Next varItem1
Next varItem2 'I know this won't work, it's just for ilustration
Next varItem3 'I know this won't work, it's just for ilustration
Thank you.