Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
Discussion GroupsFormsForms ProgrammingQueriesModules / DAO / VBAReports / PrintingMacrosDatabase DesignSecurityConversionImporting / LinkingSQL Server / ADPMultiuser / NetworkingReplicationSetup / ConfigurationDeveloper ToolkitsActiveX ControlsNew UsersGeneral 1General 2
Access DirectoryToolsTutorialsUser Groups
Related Topics
SQL ServerOther DB ProductsMS OfficeMore Topics ...

MS Access Forum / Forms Programming / September 2005

Tip: Looking for answers? Try searching our database.

INSERT INTO / Key Violation

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Vel. - 01 Sep 2005 15:11 GMT
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
Vel. - 01 Sep 2005 15:30 GMT
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.

> 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."
[quoted text clipped - 6 lines]
> "', " & dblPostAmount & ", " & dtPaidOn & ");"
>         DoCmd.RunSQL stSQLAdd
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.