How to find duplicate records in access database using vb6

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • prabhu kannan
    New Member
    • Jun 2013
    • 1

    #1

    How to find duplicate records in access database using vb6

    pls help me to find the duplicate record in vb6 i'm using access 2007. and my code is..
    Code:
    If (rs2.Fields(0) = copnme_txt.Text) Then
    reset
    Else
    rs2.AddNew
    rs2.Fields(0) = copnme_txt.Text
    rs2.Update
    reset
    End If
    reset is the function to reset all the textbox. In the code if condition is checking but it is strucking in
    rs2.update. i've made the column as primary key. so primary key is arising.. pls it is very pls help me.. thanks in advance..
  • Mihail
    Contributor
    • Apr 2011
    • 759

    #2
    Your post has been viewed 120 times in one day. And... no answer.
    That means that something is wrong with your post, because seems to be a simple question for experts.

    Since I don't use VB with databases (I use VBA) is possible to misunderstand your code.
    Any way... I think that you don't scan the entire Field(0).
    In my opinion that must be done in a cycle (starting with first record and ending with the last record) and I don't see any cycle in your code.

    Again, it is possible that I don't interpret correctly the instruction If (rs2.Fields(0) = copnme_txt.Text ) Then

    Comment

    • Killer42
      Recognized Expert Expert
      • Oct 2006
      • 8429

      #3
      Can you please explain what you mean when you says "it is strucking" on the Update statement? Is it producing an error? If so, what error?

      If the problem is that you're attempting to create a duplicate record, then it may be because you're only comparing your text (copnme_txt.Text) to the current record. What about all the other records?

      I'd suggest considering one of the following approaches:
      • Check for a duplicate by using a Find - you might want to put this in a Function to keep your code simple. So you can say for example
        Code:
        If RecordAlreadyExists(copnme_txt.Text) Then
          reset
        Else
          rs2.AddNew
          rs2.Fields(0) = copnme_txt.Text
          rs2.Update
          reset
        End If
      • Use error-handling to trap the "duplicate record" error. For example...
        Code:
        On Error Resume Next ' Turn on error trapping
        rs2.AddNew
        rs2.Fields(0) = copnme_txt.Text
        rs2.Update
        If Error.Number <> [[i][B]I forget the number[/B][/i]] Then
          Debug.Print Error.Description
        End If
        On Error Goto Next ' Turn off error trapping
        reset

      Comment

      Working...