Question : Find Duplicate values

I am working on a users DB that has a large table (6,800+ records) that theyd like to find the duplicates to that they can eventually delete them.

We are using Access 2007.  In the past (and past Access versions) Ive used a find duplicates query and after I've verified the results I change to a delete query and all is well.  With the users query it deletes values it shouldnt.  For example there are 8 items for 1 entry and it deletes all 8!  
      
I have recreated the find duplicates query from scratch since the users query was suspect and I get the same results.  This table has ID, Name, Address, City, State, Zip.  I have used all the fields and just a varying combination of some and none of these work since the data entered isnt always consistent (zip in some fields and zip+4 in others; street abbreviations, etc.).  Using just the name or name and ID doesnt work either.

Is there an issue with Access 2007's Find Duplicate Query Wizard?  
Thoughts? Suggestions?

Thanks in advance.
David

Answer : Find Duplicate values

Insert this code in a module

Option Compare Database
Option Explicit

Public Sub DelDups(tblName As String, fldName As String)
Dim db As DAO.Database, rs As DAO.Recordset, fldval As Variant, strSQL As String
strSQL = "SELECT " & fldName & " FROM " & tblName & " ORDER BY " & fldName & ";"
Set db = CurrentDb
Set rs = db.OpenRecordset(strSQL, dbOpenDynaset)
rs.MoveLast
rs.MoveFirst
If rs.RecordCount = 0 Then MsgBox "Table " & tblName & "is empty.": Exit Sub
Do
  fldval = rs(fldName).Value
  rs.MoveNext
  If rs.EOF Then Exit Do
  If rs(fldName).Value = fldval Then rs.Delete: rs.MoveNext
 
Loop While Not rs.EOF
rs.Requery
Set rs = Nothing
Set db = Nothing

End Sub

Run the code by typing this in the Immediate Pane:

DelDups "tblName", "fldName"
Random Solutions  
 
programming4us programming4us