Results 1 to 11 of 11

Thread: [RESOLVED] Delete Duplicate records

Threaded View

  1. #10

    Thread Starter
    Frenzied Member
    Join Date
    Feb 2007
    Location
    Malaysia
    Posts
    1,370

    Re: Delete Duplicate records

    Why I cannot delete all records contains duplicated record? I only able to delete half of them.
    Code:
    Private Sub Command1_Click()
    On Error Resume Next
    Set db = New ADODB.Connection
    db.Open "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & App.Path & "\DBMS.mdb;Persist Security Info=False"
    Set rst = New ADODB.Recordset
    rst.Open "Select * from A", db, adOpenDynamic, adLockOptimistic
    
      Dim strDupName As String, strSaveName As String
      If rst.BOF And rst.EOF Then
      MsgBox "No records to process"
      Else
      MsgBox "DUPLICATE FOUND DELETE"
        rst.MoveFirst
        Do Until rst.EOF
          strDupName = rst.Fields(0) & rst.Fields(1) & rst.Fields(2)
          If strDupName = strSaveName Then
            rst.Delete
          Else
            strSaveName = rst.Fields(0) & rst.Fields(1) & rst.Fields(2)
          End If
          rst.MoveNext
        Loop
        
        Set rst = Nothing
        Set db = Nothing
        
    
      End If
    
    End Sub
    Attached Files Attached Files
    Last edited by matrik02; Feb 15th, 2008 at 02:38 PM.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width