Below in blue is the code I am running:
Private Sub AddtoEvents()
Dim db As DAO.Database
Dim qd_AttendanceUpdate As DAO.QueryDef
Dim prm As DAO.Parameter
Dim AttendanceUpdate As DAO.Recordset
Me.Event_ID = Forms!frm_hidden.txt2_Hidden
Set db = CurrentDb
Set qd_AttendanceUpdate = CurrentDb.QueryDefs("qry_Attendance_0")
For Each prm In qd_AttendanceUpdate.Parameters
prm.Value = Forms!frm_hidden.txt2_Hidden
Next prm
Set AttendanceUpdate = qd_AttendanceUpdate.OpenRecordset
With AttendanceUpdate
.AddNew
!Member_ID = Forms!frm_hidden.txt0_Hidden
!Event_ID = Forms!frm_hidden.txt2_Hidden
.Update
End With
AttendanceUpdate.Close
Set AttendanceUpdate = Nothing
qd_AttendanceUpdate.Close
Set qd_AttendanceUpdate = Nothing
Set prm = Nothing
db.Close
Set db = Nothing
End Sub
When run it adds two, 2, records to the recordset, the next time it is run, one of the those records is overwritten, but the new record is added twice, and so on.
What to do????
Private Sub AddtoEvents()
Dim db As DAO.Database
Dim qd_AttendanceUpdate As DAO.QueryDef
Dim prm As DAO.Parameter
Dim AttendanceUpdate As DAO.Recordset
Me.Event_ID = Forms!frm_hidden.txt2_Hidden
Set db = CurrentDb
Set qd_AttendanceUpdate = CurrentDb.QueryDefs("qry_Attendance_0")
For Each prm In qd_AttendanceUpdate.Parameters
prm.Value = Forms!frm_hidden.txt2_Hidden
Next prm
Set AttendanceUpdate = qd_AttendanceUpdate.OpenRecordset
With AttendanceUpdate
.AddNew
!Member_ID = Forms!frm_hidden.txt0_Hidden
!Event_ID = Forms!frm_hidden.txt2_Hidden
.Update
End With
AttendanceUpdate.Close
Set AttendanceUpdate = Nothing
qd_AttendanceUpdate.Close
Set qd_AttendanceUpdate = Nothing
Set prm = Nothing
db.Close
Set db = Nothing
End Sub
When run it adds two, 2, records to the recordset, the next time it is run, one of the those records is overwritten, but the new record is added twice, and so on.
What to do????