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


January 17th, 2000, 12:51 PM
I am a novice using VB6....

I have an ACCESS database setup and a form that updates the database. I am looking for soke 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 )...

Thnak you in advance...

Terror-X
March 24th, 2000, 03:14 AM
put this in the sub where the error occurs


'put this at the top
on error goto ADOerror
'you can write here the rest of the code
exit sub
:ADOerror
if err.number = 'put here the number that the error returns
msgbox "Duplicate key in table" & vbcrlf & err.description, vbokonly, "error " & err.number
end if

March 24th, 2000, 10:34 AM
I think this only works when you save your recordset, not with immediate effect
as your control losts its focus.

Johnny101
March 24th, 2000, 11:14 AM
You can write a quick SQL Statement to test the value they enter though. do a select statement with the where clause value equal to the value the user entered. if you get something back, then it's a dupliate, if not, then it's okay.

John

John Pirkey
MCSD
www.ShallowWaterSystems.com