Click to See Complete Forum and Search --> : ADO Duplicate key


Al Lawrence
January 17th, 2000, 01:00 PM
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

Johnny101
January 17th, 2000, 03:24 PM
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

January 17th, 2000, 05:36 PM
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