key violation help needed

tricky354

Registered User.
Local time
Today, 00:39
Joined
Apr 18, 2007
Messages
18
i'm using the following SQL to INSERT dat from one table to another ( basically confirming an order from a quote ) but keep getting a key violation

Both tables have the same field names, labelled like this:

inventory_quoteBox
------------------
quoteId (autonumber)
quoteId (text)
quoteNumber (number)

inventory_sales
---------------

quoteId (number)
quoteId (text)
quoteNumber (number)

Here's my SQL called from my button


Private Sub cmdConfirmQuote_Click()
On Error GoTo Err_cmdConfirmQuote_Click

DoCmd.RunSQL "INSERT INTO inventory_sales (clientId, quoteNumber) VALUES ([inventory_quoteBox]![clientId],[inventory_quoteBox]![quoteNumber])"

Exit_cmdConfirmQuote_Click:
Exit Sub

Err_cmdConfirmQuote_Click:
MsgBox Err.description
Resume Exit_cmdConfirmQuote_Click

End Sub

can anyone help me on this - i'm pulling my hair out
 
You're not inserting a value for the quoteId.
By the looks of the error this means that quoteId is a primary key.
 
Tricky,

It looks like you're trying to insert from one table to another.

You should be inserting from your form to a table.

Code:
DoCmd.RunSQL "INSERT INTO inventory_sales (clientId, quoteNumber) " & _
                "VALUES (" & Me.[clientId] & ", " & Me.[quoteNumber] & ")"

The above assumes that both fields are numeric (i.e. no single-quotes for delimiters).

hth,
Wayne
 

Users who are viewing this thread

Back
Top Bottom