Results 1 to 3 of 3

Thread: [RESOLVED] Verify identical records in one database ???

  1. #1

    Thread Starter
    Hyperactive Member DubweiserTM's Avatar
    Join Date
    Dec 2005
    Location
    St-Ferdinand, Québec
    Posts
    427

    Resolved [RESOLVED] Verify identical records in one database ???

    Hi everybody !

    I want to verify in one database if there is identical records and keep only one of them...

    Here below it's what I tried (Sorry some words are in french):

    VB Code:
    1. 'Instanciation des variables
    2. Set cn = New ADODB.Connection
    3. Set cn1 = New ADODB.Connection
    4. Set rs = New ADODB.Recordset
    5. Set rs1 = New ADODB.Recordset
    6. 'Connection Database
    7. cn.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;" & "Data Source=" & ImpressionMDB
    8. cn.Open
    9. cn1.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;" & "Data Source=" & ImpressionMDB
    10. cn1.Open
    11. 'Ouverture des recordset
    12. rs.Open "Items", cn, adOpenKeyset, adLockPessimistic, adCmdTable
    13. rs1.Open "Items", cn1, adOpenKeyset, adLockPessimistic, adCmdTable
    14. 'Vérifier si item identique
    15. rs.MoveFirst
    16.         Do Until rs.EOF
    17.                 rs1.MoveFirst
    18.                 Do Until rs1.EOF
    19.                         [U]If rs.Fields("Description").Value = rs1.Fields("Description").Value Then[/U]
    20.                                 rs.Delete
    21.                         End If
    22.                         rs1.MoveNext
    23.                 Loop
    24.                 rs.MoveNext
    25.         Loop
    26. 'Fermeture de la connection
    27. cn.Close
    28. cn1.Close
    29. rs.Close
    30. rs1.Close
    31. Set cn = Nothing
    32. Set cn1 = Nothing
    33. Set rs = Nothing
    34. Set rs = Nothing
    I got an error on the underlined line:

    Runtime Error -2147217885 (80040e23) : A Given HROW Referred to a Hard-Deleted or Soft-Deleted Row

    If you have other suggestion, let me know !

    Thanks in advance !
    DubweiserTM

    If your question has been answered, you can mark a thread as resolved...

  2. #2
    Super Moderator FunkyDexter's Avatar
    Join Date
    Apr 2005
    Location
    An obscure body in the SK system. The inhabitants call it Earth
    Posts
    7,957

    Re: Verify identical records in one database ???

    Your logic is wrong. You open th same table in both recordsets and then, for each record in rs you check if there's a record with the same values in rs1. There will be but it'll be the same record rather than a duplicate. Your actually quite lucky it didn't run becuase that would have deleted all your data.

    You need to take a slightly different approach. I would recommend using a:-
    Code:
    SELECT *
    FROM Items 
    INTO tempTable
    GROUP BY field1,field2,field3...etc
    To create a new table. You will need to replace the Field1,field2 etc with a list of all the fields in your table. Because you've used a group by with all the fields in it this will create a new table with no duplicate records. You can then delete your original Items table and replace it with the contents of the new tempTable.

  3. #3

    Thread Starter
    Hyperactive Member DubweiserTM's Avatar
    Join Date
    Dec 2005
    Location
    St-Ferdinand, Québec
    Posts
    427

    Re: Verify identical records in one database ???

    Quote Originally Posted by FunkyDexter
    Your logic is wrong. You open th same table in both recordsets and then, for each record in rs you check if there's a record with the same values in rs1. There will be but it'll be the same record rather than a duplicate. Your actually quite lucky it didn't run becuase that would have deleted all your data.
    Oooopppsss ! I want to try something instead to ask someone to make it for me...

    Quote Originally Posted by FunkyDexter
    You need to take a slightly different approach. I would recommend using a:-
    Code:
    SELECT *
    FROM Items 
    INTO tempTable
    GROUP BY field1,field2,field3...etc
    To create a new table. You will need to replace the Field1,field2 etc with a list of all the fields in your table. Because you've used a group by with all the fields in it this will create a new table with no duplicate records. You can then delete your original Items table and replace it with the contents of the new tempTable.
    I'll try that ! Thanks !
    DubweiserTM

    If your question has been answered, you can mark a thread as resolved...

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