koolwaters
Active Member
- Joined
- May 16, 2007
- Messages
- 403
Hi,
I have a bound subform which contains a multiselect listbox.
I am trying to insert the values from this multiselect listbox along with one other value into a table.
The values I am trying to insert are:
the foreign key field
the value/values selected in the listbox
I am using the code below in the Before Update property of the subform but if more than one item is selected in the listbox only one is inserted into the table and I get an error "Index or primary key cannot contain a Null value".
Any suggestions?
Thanks
I have a bound subform which contains a multiselect listbox.
I am trying to insert the values from this multiselect listbox along with one other value into a table.
The values I am trying to insert are:
the foreign key field
the value/values selected in the listbox
I am using the code below in the Before Update property of the subform but if more than one item is selected in the listbox only one is inserted into the table and I get an error "Index or primary key cannot contain a Null value".
Code:
Private Sub Form_BeforeUpdate(Cancel As Integer)
Dim varItem As Variant
Dim strSQL As String
For Each varItem In Me.SOID.ItemsSelected
strSQL = "INSERT INTO tblMatSO (MatID, SOID) " _
& "Values(" & Me.MatID & ", " _
& Me.SOID.Column(0, varItem) & ")"
Next
DoCmd.RunSQL strSQL
End Sub
Any suggestions?
Thanks