INSERT INTO / Key Violation

V

Vel.

When I use the code below in an AfterUpdate event on a form, I get an error
stating that the Append query "didn't add 1 record(s) due to key violations."

The primary key of tblPayments is an autonumber field... is there something
inherently wrong in this statement, or am I missing something?

stSQLAdd = "INSERT INTO tblPayments ( ActivityID, InsuranceID,
EntBy, Payment, PaidOn ) VALUES (" & stActivityID & " , 'NA', '" & stEntBy &
"', " & dblPostAmount & ", " & dtPaidOn & ");"
DoCmd.RunSQL stSQLAdd
 
V

Vel.

Nevermind... I'm an idiot... well... maybe not an idiot, but I just
overlooked something. Instead of setting the value of ActivityID to the
correct number, I had stored the value ClientID in the field ActivityID.
Since tlbActivity and tblPayments are in a one-to-many relationship with one
another, I couldn't append tblPayments without an appropriate ActivityID.
 
Top