Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations MikeeOK on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Record Key Violation

Status
Not open for further replies.

CrAzIcRaCkEr

IS-IT--Management
Jul 18, 2006
3
US
I have been battling this problem all day today. I am running Access 2002 w/SP3. I have a SQL statement in the VBA code. The statement reads:

DoCmd.RunSQL ("UPDATE VMVendors SET COMPANY = '" & vdrName & "' WHERE [VENDNO] = '" & VENDORID & "'")

When this command is executed I get the infamous "Key Violation" error. The Variable "VENDORID" is found in the table one time and it is the primary key within the table. The table is called VMVendors. The Field is named COMPANY. The Primary key in the table is named VENDNO. I have two variables. One is vdrName which is a string. The other is VENDORID which is a string as well.

I should not be receiving a Key Violation on an UPDATE statement. I did go in and check the relationships. All relationships are connected to the VENDORID in other tables. It is not set to populate other tables or cascade to other tables.

Funny thing is that this code:

DoCmd.RunSQL ("UPDATE VMVendors SET ADDR1 = '" & addy1 & "' WHERE [VENDNO] = '" & VENDORID & "'")

Executes just before the previous code flawlessly. So this means that I have a problem with the variable that I am trying to set in the previous code?!? ...vdrName...

The value of vdrName = "Bright Ideas in Broad Ripple" In the database the COMPANY field is the field that
I am trying to line up with the vdrName. COMPANY is set as a text field with 50 characters available.

Any ideas or help on this issue would be much appreciated.

Cc
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top