Alienz wrote:
I have a subform where I have a subform with 20 options to select
from. When I set the multiselect property to simple and select
multiple options, nothing is stored. I have another table with
fieldID and fieldtype and I would like for evertime something is
selected in the listbox for a new entry to be created with that
fieldtype for the corresponding fieldID which is linked to the main
form. Basically, how do I get info from the listbox to go into the
subform and create new entries?? thanks anyone
Here is a sample routine I used. I have ColumnHeaders on in my listbox
so that is why I start intFor at 1 and 0. I want to add the record
with the order number if selected in a multi-select listbox and if it
does not exist. If it does exist, but this time is not selected, I want
to remove it from the table.
If you don't have the need to remove selections if they exist in the
table but aren't selected, you can change ListCount -1 and use
ItemsSelected. Review these commands in Help. Ex:
Dim Var As Variant
For each var in Me.ListBox.ItemsSelected
'get the value in the second col of the listbox
'since columns start at 0
strValue = Me.ListBox.Column(1,var)
Next
Anyway, here's the code.
Sub x()
Dim intFor As Integer
Dim strOrder As String
Dim rst As Recordset
Dim blnSelected As Boolean
For intFor = 1 To Me.ListBox.ListCount - 1
strOrder = Me.ListBox.Column(0, intFor)
blnSelected = Me.ListBox.Selected(intFor)
rst.FindFirst "OrderID = '" & strOrder & "'"
If rst.NoMatch Then
If blnSelected Then
rst.AddNew
rst!OrderID = strOrder
rst.Update
End If
Else
If Not blnSelected Then
rst.Delete
End If
End If
Next intFor
End Sub