avoid duplicate entry in vb6

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • prafulla1978
    New Member
    • Nov 2014
    • 2

    avoid duplicate entry in vb6

    sir,
    i am developed a application in visual basic 6.0 but at last iam facing a problem when a user search data that display in all textboxes form ms access database.
    but when he click on save button the old data (searched) also saved or when he enter the new data it gets saved any problem to this i have following code
    Visual basic 6.0
    do while not rs.eof
    if rs.field(1).val ue=txtcustname. text then
    msgbox " this is duplicate entry"
    end if
    exit sub
    loop
    but in this case if the entry is already present in database it hang in loop and application hangs up
    i want quick solution plz send me solution as early as possible
    thanks you
    Last edited by Rabbit; Nov 23 '14, 04:56 PM. Reason: Email removed per forum policy
  • twinnyfo
    Recognized Expert Moderator Specialist
    • Nov 2011
    • 3653

    #2
    prafulla1978,

    I'm not sure how your code could be hanging up, since you tell your code to exit the sub no matter what the result of the If...Then is. You also do not appear to be doing anything else once a duplicate is found, other than notifying the user. You are also never moving to the next record.

    So, it is unclear as to what the problem is with your code, as it appears there are many.

    Comment

    • kadghar
      Recognized Expert Top Contributor
      • Apr 2007
      • 1302

      #3
      Try a FOR EACH, and leave the EXIT SUB inside the IF (I'd rather use an EXIT FOR).

      Comment

      • prafulla1978
        New Member
        • Nov 2014
        • 2

        #4
        i have deloped the above code :
        Code:
        dim name as string
        dim str as string
        dim rs as recordset
        dim rs as new adodb.recordset
        str="Select name from table1 where name='" & txtname.text &"'"
        rs.open str,db, adopenstatic , adlockoptimistic
        name=rs.field(1).value
        if name=txtname then
        exit sub
        else
        rs.addnew
        end if
        Last edited by Rabbit; Nov 25 '14, 06:31 PM. Reason: Please use [code] and [/code] tags when posting code or formatted data.

        Comment

        • twinnyfo
          Recognized Expert Moderator Specialist
          • Nov 2011
          • 3653

          #5
          prafulla,

          First, please use code tags when posting code to this forum.

          Second, if the code above is what you are actually using, one of the biggest glaring problems I see is that you are using the reserved word "Name" as one of your field names. This can cause very many unexpected errors and problems when writing code (and is probably a significant contributing factor to your problem here.

          I would recommend changing the "Name" Field in table1 to something like "UserName", just to make sure the VBA can differentiate between that field and another reserved word.

          Hope this hepps!

          Comment

          Working...