CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3
  1. #1
    Join Date
    Jan 2000
    Posts
    1

    ADO Duplicate key

    I am a novice using VB6....

    I have an ACCESS database setup and a form that updates the database. I am looking for some example code that will help me trap a "duplicate key" error and format the error in a readable format (other than what is normally returned )...

    Thank you in advance...





    Regards,

    Al

  2. #2
    Join Date
    Jan 2000
    Location
    MO, USA
    Posts
    1,506

    Re: ADO Duplicate key

    Setup an error handler and test for the error number for the duplicate key error...

    private Sub UpdateDB()
    'declarations
    on error Goto Update_Error
    'do processing
    ...
    ...
    ...
    'exit before the error handling code, so that it doesn't run unless an error occurrs.
    Exit Sub

    Update_Error:
    If Err.Number = (number of duplicate key error) then
    MsgBox "You have entered a key value that already exists.", vbInformation, "error"
    'do any other clean up or retry the operation with a new value...
    End If

    End Sub




    Hope this helps,
    John


    John Pirkey
    MCSD
    www.ShallowWaterSystems.com
    John Pirkey
    MCSD (VB6)
    http://www.stlvbug.org

  3. #3
    Guest

    Re: ADO Duplicate key

    Thank you for the quick response...

    The Duplicate key error number is a long negative number.. is that the number that I shoudl use or is there a list of error code available somewhere?

    Al


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

Featured