The code below doesn't work properly because I believe that the OpenRecodset("MatterEmails") is in it's native order and I need it recin!MatterId and then recin!EmailAddress order
Can anyone help me please
Can anyone help me please
Code:
Dim db As DAO.Database
Dim recIn As DAO.Recordset
Dim strLastField1 As String
Dim strLastField2 As String
Dim strLastField3 As String
Dim lngRecordsDeleted As Long
Dim lngRecordsRead As Long
lngRecordsDeleted = 0
lngRecordsRead = 0
Set db = CurrentDb()
Set recIn = db.OpenRecordset("MatterEmails")
If recIn.EOF Then
MsgBox ("No Input Records")
recIn.Close
Set recIn = Nothing
Set db = Nothing
Exit Sub
End If
Do
If recIn!MatterId = strLastField1 And recIn!EmailAddress = strLastField2 Then
recIn.Delete
lngRecordsDeleted = lngRecordsDeleted + 1
Else
strLastField1 = recIn!MatterId
strLastField2 = recIn!EmailAddress
'strLastField3 = recIn!Field3
End If
lngRecordsRead = lngRecordsRead + 1
recIn.MoveNext
Loop Until recIn.EOF
recIn.Close
Set recIn = Nothing
Set db = Nothing
MsgBox ("You Read " & lngRecordsRead & " Matter email records and Deleted " & lngRecordsDeleted & " email records")