P
Phil
I posted yesterday with a query on my code which Douglas Steel (Thanks)
sorted for me. the code is linked to a button on a form (Events1) will
insert multiselect items from a listbox (ItemsSelected) into a table (this
part works fine). the form that the listbox is on has two other fields that
I would also like to insert into the table. the fields are EventID (number)
and CourseDate (ComboBox bound column is the one I want to insert into table)
I dont know how to refer to the fields in the code.
I hope someone can help, thanks in advance
Phil
Dim frm As Form, ctl As Control
Dim db As DAO.Database
Dim rst As DAO.Recordset
Dim varItem As Variant
Dim strTemp As String
If Me.TimetableList.ItemsSelected.Count = 0 Then
MsgBox ("Please select at least one Session.")
Exit Sub
End If
Set db = CurrentDb
Set frm = Me 'sets form to active form
Set ctl = frm!TimetableList 'Name of your listbox
Set rst = db.OpenRecordset("Sessions")
For Each varItem In ctl.ItemsSelected
db.Execute "INSERT INTO Sessions ([SessionID]) " & "VALUES(""" &
ctl.ItemData(varItem) & """)", dbFailOnError
Next varItem
sorted for me. the code is linked to a button on a form (Events1) will
insert multiselect items from a listbox (ItemsSelected) into a table (this
part works fine). the form that the listbox is on has two other fields that
I would also like to insert into the table. the fields are EventID (number)
and CourseDate (ComboBox bound column is the one I want to insert into table)
I dont know how to refer to the fields in the code.
I hope someone can help, thanks in advance
Phil
Dim frm As Form, ctl As Control
Dim db As DAO.Database
Dim rst As DAO.Recordset
Dim varItem As Variant
Dim strTemp As String
If Me.TimetableList.ItemsSelected.Count = 0 Then
MsgBox ("Please select at least one Session.")
Exit Sub
End If
Set db = CurrentDb
Set frm = Me 'sets form to active form
Set ctl = frm!TimetableList 'Name of your listbox
Set rst = db.OpenRecordset("Sessions")
For Each varItem In ctl.ItemsSelected
db.Execute "INSERT INTO Sessions ([SessionID]) " & "VALUES(""" &
ctl.ItemData(varItem) & """)", dbFailOnError
Next varItem