Append querie error

  • Thread starter Thread starter h3llz
  • Start date Start date
H

h3llz

DoCmd.RunSQL ("INSERT INTO tblProductsLog VALUES (" & [staffID] & "," &
[productID] & "," & -[productQuantity] & ",'" & Now() & "');")

staffID, productID, productQuantity are integer
 
i found the error, staffID and productID was keys and if i remove the keys it
work, but why is this? (key violations)
 
You're attempting to add a second record with the same values of staffID and
productID.

If staffID and productID are the primary key, that's not allowed. (That's
the whole point of a primary key...)

--
Doug Steele, Microsoft Access MVP

(no private e-mails, please)


h3llz said:
i found the error, staffID and productID was keys and if i remove the keys
it
work, but why is this? (key violations)

h3llz said:
DoCmd.RunSQL ("INSERT INTO tblProductsLog VALUES (" & [staffID] & "," &
[productID] & "," & -[productQuantity] & ",'" & Now() & "');")

staffID, productID, productQuantity are integer
 
The combination of basketID and productID is unique

Douglas J. Steele said:
You're attempting to add a second record with the same values of staffID and
productID.

If staffID and productID are the primary key, that's not allowed. (That's
the whole point of a primary key...)

--
Doug Steele, Microsoft Access MVP

(no private e-mails, please)


h3llz said:
i found the error, staffID and productID was keys and if i remove the keys
it
work, but why is this? (key violations)

h3llz said:
DoCmd.RunSQL ("INSERT INTO tblProductsLog VALUES (" & [staffID] & "," &
[productID] & "," & -[productQuantity] & ",'" & Now() & "');")

staffID, productID, productQuantity are integer
 
Your INSERT statement isn't setting basketID, so it'll be Null. If the value
for productID already exists in the table with a Null basketID, that's a
duplicate.

--
Doug Steele, Microsoft Access MVP

(no e-mails, please!)


h3llz said:
The combination of basketID and productID is unique

Douglas J. Steele said:
You're attempting to add a second record with the same values of staffID
and
productID.

If staffID and productID are the primary key, that's not allowed. (That's
the whole point of a primary key...)

--
Doug Steele, Microsoft Access MVP

(no private e-mails, please)


h3llz said:
i found the error, staffID and productID was keys and if i remove the
keys
it
work, but why is this? (key violations)

:

DoCmd.RunSQL ("INSERT INTO tblProductsLog VALUES (" & [staffID] & ","
&
[productID] & "," & -[productQuantity] & ",'" & Now() & "');")

staffID, productID, productQuantity are integer
 
Back
Top