I am using the following code to find and delete records in a table. The logic will go through each record and if a duplicate row is found will delete it. I ran this code and it worked the first time. Its not deleting the rows when I tried the second time. I debugged the code and its actually going through the delete step but the row is not getting deleted as it did the first time. Please help.
Thanks in advance.
Thanks in advance.
Code:
Function DeleteDuplicates_Click() On Error Resume Next Dim db As Database, rst As Recordset Dim strDupName As String, strSaveName As String Dim strSQL As String strSQL = "SELECT [JOBNUM], [trnd] FROM Tableqryduplicates" Set db = CurrentDb() Set rst = db.openrecordset(strSQL, dbOpenSnapshot) If rst.BOF And rst.EOF Then MsgBox "No records to process" Else rst.MoveFirst Do Until rst.EOF strDupName = rst.Fields("JOBNUM") & rst.Fields("trnd") If strDupName = strSaveName Then rst.Delete Else strSaveName = rst.Fields("JOBNUM") & rst.Fields("trnd") End If rst.MoveNext Loop rst.Close Set rst = Nothing Set db = Nothing End If End Function
Comment