I have a query - see coding below that saves not only new records, but also the existing records, which results in duplicate entries to the underlying table. Is there a way that I can show the existing entries, but only save the new entries.
Private Sub Save_Click()
Dim cKeyID As Long
'Update the database
Dim db As DAO.Database
Dim qdf As DAO.QueryDef
Dim prm As DAO.Parameter
Dim rst As DAO.Recordset
Dim str As String
Set db = CurrentDb
Set qdf = db.QueryDefs("EmployeeAbsence"
For Each prm In qdf.Parameters
prm.Value = Eval(prm.Name)
Next prm
Set rst = qdf.OpenRecordset(dbOpenDynaset).Clone
If rst.RecordCount > 0 Then
rst.MoveFirst
Do While Not rst.EOF
HoldDate = rst!Date
HoldApp = rst!Details
Me.ctCalendar1.DateText(HoldDate) = HoldApp
Me.ctCalendar1.DateImage(HoldDate) = rst!Image
rst.MoveNext
Loop
End If
For cKeyID = ctCalendar1.DateStart To ctCalendar1.DateEnd Step 1
If Me.ctCalendar1.DateText(cKeyID) <> Empty Or Me.ctCalendar1.DateImage(cKeyID) <> 0 Then
rst.AddNew
rst!Details = ctCalendar1.DateText(cKeyID)
rst!Image = Me.ctCalendar1.DateImage(cKeyID)
rst!Employee = Me.Employee
If ctCalendar1.DateText(cKeyID) = Empty Then
rst!Details = " "
End If
rst!Date = cKeyID
rst.Update
End If
Next
rst.Close
End Sub
Thanks
Private Sub Save_Click()
Dim cKeyID As Long
'Update the database
Dim db As DAO.Database
Dim qdf As DAO.QueryDef
Dim prm As DAO.Parameter
Dim rst As DAO.Recordset
Dim str As String
Set db = CurrentDb
Set qdf = db.QueryDefs("EmployeeAbsence"
For Each prm In qdf.Parameters
prm.Value = Eval(prm.Name)
Next prm
Set rst = qdf.OpenRecordset(dbOpenDynaset).Clone
If rst.RecordCount > 0 Then
rst.MoveFirst
Do While Not rst.EOF
HoldDate = rst!Date
HoldApp = rst!Details
Me.ctCalendar1.DateText(HoldDate) = HoldApp
Me.ctCalendar1.DateImage(HoldDate) = rst!Image
rst.MoveNext
Loop
End If
For cKeyID = ctCalendar1.DateStart To ctCalendar1.DateEnd Step 1
If Me.ctCalendar1.DateText(cKeyID) <> Empty Or Me.ctCalendar1.DateImage(cKeyID) <> 0 Then
rst.AddNew
rst!Details = ctCalendar1.DateText(cKeyID)
rst!Image = Me.ctCalendar1.DateImage(cKeyID)
rst!Employee = Me.Employee
If ctCalendar1.DateText(cKeyID) = Empty Then
rst!Details = " "
End If
rst!Date = cKeyID
rst.Update
End If
Next
rst.Close
End Sub
Thanks