Hi everyone. I need your help to the following issue. I used this example : http://www.access-programmers.co.uk/forums/showthread.php?t=165549 and more specific the last one "Using multi select moving". Now I want to put the selected values to a new table and add new rows each time I have a new event.
I tried to use the function below that I've found in another sample but doesn't seem to work.
Thanks in advance for your help.
Public Function CreateAttendanceRecords(ctlRef As ListBox) As String
On Error GoTo Err_CreateAttendanceRecords_Click
Dim i As Variant
Dim dbs As DAO.Database
Dim rst As DAO.Recordset
Dim qd As DAO.QueryDef
Set dbs = CurrentDb
Set qd = dbs.QueryDefs!qAttendance
Set rst = qd.OpenRecordset
For Each i In ctlRef.ItemsSelected
rst.AddNew
rst!fldDescription = ctlRef.ItemData(i)
st!AttendanceDate = Me.txtToday
rst.Update
Next i
Set rst = Nothing
Set qd = Nothing
CreateAttendanceRecords = "Records Created"
Exit_CreateAttendanceRecords_Click:
Exit Function
Err_CreateAttendanceRecords_Click:
Select Case Err.Number
Case 3022 'ignore duplicate keys
Case Else
MsgBox Err.Number & "-" & Err.Description
End Select
Resume Exit_CreateAttendanceRecords_Click
End Function
I tried to use the function below that I've found in another sample but doesn't seem to work.
Thanks in advance for your help.
Public Function CreateAttendanceRecords(ctlRef As ListBox) As String
On Error GoTo Err_CreateAttendanceRecords_Click
Dim i As Variant
Dim dbs As DAO.Database
Dim rst As DAO.Recordset
Dim qd As DAO.QueryDef
Set dbs = CurrentDb
Set qd = dbs.QueryDefs!qAttendance
Set rst = qd.OpenRecordset
For Each i In ctlRef.ItemsSelected
rst.AddNew
rst!fldDescription = ctlRef.ItemData(i)
st!AttendanceDate = Me.txtToday
rst.Update
Next i
Set rst = Nothing
Set qd = Nothing
CreateAttendanceRecords = "Records Created"
Exit_CreateAttendanceRecords_Click:
Exit Function
Err_CreateAttendanceRecords_Click:
Select Case Err.Number
Case 3022 'ignore duplicate keys
Case Else
MsgBox Err.Number & "-" & Err.Description
End Select
Resume Exit_CreateAttendanceRecords_Click
End Function