Results 1 to 3 of 3

Thread: Primary key error

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Jul 2000
    Location
    Australia
    Posts
    69

    Angry

    I have a datagrid with some records...if I add a record with a duplicate primary key I get an ODBC error informing that I have attempted to adda record with duplicate key...I'm happy with this BUT...the there are no error numbers or any visible way I can set up an error trap for this situation..is there a way that I can trap this error!

    I'm using an Access 97 database with ADO as my method of access.

    Ta

    Gerard

  2. #2
    Randalf the Red honeybee's Avatar
    Join Date
    Jun 2000
    Location
    off others' brains
    Posts
    4,345

    Well ....

    The simplest way to avoid that error is to generate the primary key through your application so that it is unique.

    You can use the On Error statement, or use the RDO Errors collection object to trap the errors. For more help refer to the MSDN help and still if it doesn't help, we are here to help you out.

    I am not a complete idiot. Some parts are still missing.
    Check out the rtf-help tutorial
    General VB Faq Thread
    Change is the only constant thing. I have not changed my signature in a long while and now it has started to stink!
    Get more power for your floppy disks. ; View honeybee's Elite Club:
    Use meaningfull thread titles. And add "[Resolved]" in the thread title when you have got a satisfactory response.
    And if that response was mine, please think about giving me a rep. I like to collect them!

  3. #3
    Frenzied Member
    Join Date
    Aug 1999
    Location
    Santa Clara, Ca , 95058
    Posts
    1,105
    Originally posted by gerard
    I have a datagrid with some records...if I add a record with a duplicate primary key I get an ODBC error informing that I have attempted to adda record with duplicate key...I'm happy with this BUT...the there are no error numbers or any visible way I can set up an error trap for this situation..is there a way that I can trap this error!

    I'm using an Access 97 database with ADO as my method of access.

    Ta

    Gerard
    Check the value of Err.number in debug, after you attempt to add a duplicate key. Then add code to check for that value.

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