PDA

Click to See Complete Forum and Search --> : Primary key error


gerard
Aug 11th, 2000, 02:29 AM
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

honeybee
Aug 11th, 2000, 06:39 AM
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.

JHausmann
Aug 11th, 2000, 11:43 AM
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.