Run time error -2147217887 (80040e21)

D

Dave

Hi I am trying to add a record to a table

My code is as follows:

Dim rs As New ADODB.Recordset

rs.Open "SELECT EmpJobID, JobID, EmpID FROM tblEmpJob",
CurrentProject.Connection, adOpenKeyset, adLockPessimistic
With rs
.AddNew
!JobID = lngJobID
!EmpID = intEmpToID
.Update
End With
rs.Close
Set rs = Nothing

It is failing on the update. The error is

Run Time error -2147217887 (80040e21)

The changes you requested to the table were not successful because
they would create duplicate values in the index, primary key or
relationship. Change the data in the field, or fields that copntacin
the duplicate data, remove the index, or redefine the index to permit
duplicate entries and try again.

Neither JobID nor EmpID are unique.

This code has run before many hundreds of times - the only thing I can
think of is that the table is now getting large, with the unique key
(which is an autonumber) now at 264135

Thanks
 
B

Bill Johnson

Dave, I had the same error, I added an error handler to the end of the code
and it works fine.

Error_Handler:
Select Case (Err.Number)
Case -2147217887
Resume Next
Case Else
MsgBox "You have encountered an error. " & Chr(13) & _
"Error Number : " & Err.Number & Chr(13) & _
"Error Description : " & Err.Description
Resume Exit_cmbRptName_AfterUpdate
End Select
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top