
Originally Posted by
June7
First: Selecting multiple items in a multi-select listbox and then creating records from those selections requires VBA code that loops through the selected items and writes records to table.
Second: The dates can be saved in the records with the same code procedure.
Something like:
Code:
Dim varItem As Variant
'Loop through the ItemsSelected in the list box.
With Me.lstStaff
For Each varItem In .ItemsSelected
If Not IsNull(varItem) Then
'save record to table
CurrentDb.Execute "INSERT INTO tableC(StaffID, TaskID, DateStart, DateEnd) Values(" & varItem & ", " & Me.tbxTask & ", #" & Me.tbxStart & "#, #" & Me.tbxEnd & "#"
End If
Next
End With
I tried this with the INSERT INTO and only with the employee ID (without assigning any dates), but nothing happens. That's what I got:
Code:
Private Sub btn_slct_Click()
Dim varItem As Variant
With Me.lstbx_EMPLOYEES
For Each varItem In .ItemsSelected
If Not IsNull(varItem) Then
CurrentDb.Execute "INSERT INTO tbl_slct[(EMPLOYEES_ID)] SELECT [tbl_EMPLOYEES.]EMPLOYEES_ID FROM tbl_EMPLOYEES"
End If
Next
End With
End Sub
I think the "FROM tbl_EMPLOYEES" is definitely wrong