I have a table with duplicate records but also semi duplicate records.
SpNo SpDate DateAuth Result CulComment
B1445677 15/06/2020 26/06/2020 NO res myo comm
B1445677 15/06/2020 26/06/2020 -------- myo comm
B1445677 15/06/2020 23/06/2020 -------- myo comm
What I'm trying to do is delete from the table the 3rd (oldest) and second record leaving the first only (The system is old and kicks out both the ------ and then the No Res. the "--------" is always the same length the No Res can say anything etc
The table has 1000's of records
I can scroll though and look for pure duplicate and delete them easily but problem I'm having is the task with the records as above.
Sub DeleteDupRec(Tablename As String)
Dim rst As DAO.Recordset
Dim rst2 As DAO.Recordset
Dim tdf As DAO.TableDef
Dim fld As DAO.Field
Dim strSQL As String
Dim varBookmark As Variant
Set tdf = DBEngine(0)(0).TableDefs(strTableName)
strSQL = "SELECT * FROM " & strTableName & " ORDER BY "
For Each fld In tdf.Fields
If (fld.Type <> dbMemo) And (fld.Type <> dbLongBinary) Then
strSQL = strSQL & fld.Name & ", "
End If
Next fld
strSQL = Left(strSQL, Len(strSQL) - 2)
Set tdf = Nothing
Set rst = CurrentDb.OpenRecordset(strSQL)
Set rst2 = rst.Clone
rst.MoveNext
Do Until rst.EOF
varBookmark = rst.Bookmark
For Each fld In rst.Fields
If fld.Value <> rst2.Fields(fld.Name).Value Then
GoTo NextRecord
End If
Next fld
rst.Delete
GoTo stopmk
NextRecord:
rst2.Bookmark = varBookmark
stopmk:
rst.MoveNext
Loop
End Sub
SpNo SpDate DateAuth Result CulComment
B1445677 15/06/2020 26/06/2020 NO res myo comm
B1445677 15/06/2020 26/06/2020 -------- myo comm
B1445677 15/06/2020 23/06/2020 -------- myo comm
What I'm trying to do is delete from the table the 3rd (oldest) and second record leaving the first only (The system is old and kicks out both the ------ and then the No Res. the "--------" is always the same length the No Res can say anything etc
The table has 1000's of records
I can scroll though and look for pure duplicate and delete them easily but problem I'm having is the task with the records as above.
Sub DeleteDupRec(Tablename As String)
Dim rst As DAO.Recordset
Dim rst2 As DAO.Recordset
Dim tdf As DAO.TableDef
Dim fld As DAO.Field
Dim strSQL As String
Dim varBookmark As Variant
Set tdf = DBEngine(0)(0).TableDefs(strTableName)
strSQL = "SELECT * FROM " & strTableName & " ORDER BY "
For Each fld In tdf.Fields
If (fld.Type <> dbMemo) And (fld.Type <> dbLongBinary) Then
strSQL = strSQL & fld.Name & ", "
End If
Next fld
strSQL = Left(strSQL, Len(strSQL) - 2)
Set tdf = Nothing
Set rst = CurrentDb.OpenRecordset(strSQL)
Set rst2 = rst.Clone
rst.MoveNext
Do Until rst.EOF
varBookmark = rst.Bookmark
For Each fld In rst.Fields
If fld.Value <> rst2.Fields(fld.Name).Value Then
GoTo NextRecord
End If
Next fld
rst.Delete
GoTo stopmk
NextRecord:
rst2.Bookmark = varBookmark
stopmk:
rst.MoveNext
Loop
End Sub