Hi rpear,
Finally got around to trying this out with my own data and i ran into a couple issues.
Not sure why but the code is marking some records as invalid that dont have duplicate ClaimNumbers. Its only 2/18000 record but i cant seem to find a reason why. Also the code wasnt picking up all the dates that were 2 days or less so i changed the code to < 3 days and now it seems to be picking up duplicates that are 3 days apart. Dates are stored as short dates with no times. They all default to 12:00 AM if using Extended Time so i cant seem to figure this out.
Any idea why this might be happening?
Code:
Function CleanUp()Dim db As Database
Dim rst As Recordset
Dim sPrevClaimNum As String
Dim dPrevDate As Date
Dim iPrevPK As Long
Dim sCurrClaimNum As String
Dim dCurrDate As Date
Dim iCurrPK As Long
Set db = CurrentDb
Set rst = db.OpenRecordset("SELECT * FROM NCATTrendingLog ORDER BY ClaimNumber, DateAssigned")
sPrevClaimNum = rst.Fields("ClaimNumber")
dPrevDate = rst.Fields("DateAssigned")
iPrevPK = rst.Fields("AutoNum")
Do While rst.EOF <> True
sCurrClaimNum = rst.Fields("ClaimNumber")
dCurrDate = rst.Fields("DateAssigned")
iCurrPK = rst.Fields("AutoNum")
If sCurrClaimNum = sPrevClaimNum Then
If dPrevDate + 3 < dCurrDate Then
dPrevDate = dCurrDate
iPrevPK = iCurrPK
rst.MoveNext
Else
db.Execute ("UPDATE NCATTrendingLog SET Invalid = -1 WHERE AutoNum = " & iPrevPK)
sPrevClaimNum = sCurrClaimNum
dPrevDate = dCurrDate
iPrevPK = iCurrPK
rst.MoveNext
End If
Else
If DCount("*", "NCATTrendingLog", "[AutoNum] = " & iCurrPK) = 1 Then
sPrevClaimNum = sCurrClaimNum
dPrevDate = dCurrDate
iPrevPK = iCurrPK
rst.MoveNext
Else
MsgBox "HERE"
End If
End If
Loop
rst.Close
Set rst = Nothing
Set db = Nothing
End Function