Key Violation Question

N

nick

What causes them?

I have an insert statement that call of a sudden won't work for me because
of a key violation. It's very simple

DoCmd.RunSQL ("INSERT INTO Project_Main (Client_Code)" & _
" Values (" & Chr$(34) & Client_Code & Chr$(34) & ")")

All the other Insert statements I've used work great. What is the normal
cause for this error?
 
V

V Ramos

nick said:
What causes them?

I have an insert statement that call of a sudden won't work for me because
of a key violation. It's very simple

DoCmd.RunSQL ("INSERT INTO Project_Main (Client_Code)" & _
" Values (" & Chr$(34) & Client_Code & Chr$(34) & ")")

All the other Insert statements I've used work great. What is the normal
cause for this error?

There are several reasons for key violation error:
1. You may be inserting records that has duplicates in the target table and
you enforced a "no duplicate" rule in one of the target table indexes
2. The append query will create orphan records in the target table (if the
target table has referential integrity to other tables in the database.
 
J

Jeff Boyce

Yet another scenario:

you have a "required" field in the table, but no value is being inserted

Good luck

Jeff Boyce
<Access MVP>
 

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