UpdateDuplicate

kingesk
03-07-2001, 06:34 PM
I am attempting to code some error handeling when a user trys to AddNew and Update with a primary key that already exist.
The error num I got was '-2147467259(800004005)'
I can't seem to trap this error. Any ideas on how to handle this?

Thanks,

Eric



Private Sub mnuUpdate_Click()
'save the added record

On Error GoTo HandleErrors

mRstCurrent("PubId") = txtID
mRstCurrent("Name") = txtName
mRstCurrent("company Name") = txtCoName
mRstCurrent("Address") = txtAddress

mRstCurrent.Update

txtID.SetFocus
lblRecCount = mRstCurrent.RecordCount
lblRecNum = mRstCurrent.AbsolutePosition

Exit Sub

HandleErrors:
Select Case Err:

Case "'-2147467259(80004005)'"
MsgBox "ID already exist, pick id with a unique value", vbOKOnly
mRstCurrent.CancelUpdate
txtID.SetFocus
Exit Sub
Case Else 'all other errors should cancel execution
Err.Raise Err
End Select
Resume

End Sub

PWNettle
03-08-2001, 10:09 AM
One way to handle this without using error trapping would be to run a query against the table using the intended key value before the attempted add. If you get a record back from the select you'd know that a record with that key already exists and could respond as you like. If you don't get a record back you know that you can use that key and go ahead and add the new record.

Paul

klabranche
03-08-2001, 03:52 PM
take out the (800004005) from the case statement and it should work.

http://www.extreme-vb.net/images/icons/smile.gif

kingesk
03-09-2001, 07:36 AM
Thanks,

You were both very helpful.

Eric

EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum