Transfer data from one table to another with Insert Into

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Help, I have an application that first sets up a quote, then if the quote
becomes a sale, the info transfers from the quote table to sales table. I
had this code working, but now I get the following error:
"The changes you requested to the table were not successful because they
would create duplicate values in the index, primary key, or relationship.
Change the data in the field or fields that contain the duplicate data,
remove the index, or redefine the index to permit duplicate entries and try
again."

Code:
Private Sub ProcessSale_Click()
On Error GoTo Err_ProcessSale_Click
Dim dbs As Database
Dim LInsert As String
Dim payfields As String
Dim qfields, sfields As String
Dim sid As Long
'Insert the Quote data into the Sales table
Set dbs = CurrentDb()
ifields = "CustomerID, ProductID, SaleDate, MileageOut, SalesPrice,
TradeInAllowance, SalesTax, TagTitleReg, DownPayment, DealersComp,
TotalPayments, PaymentPer, FirstPaymentDate"
LInsert = "Insert Into tblSales (" & ifields & ") Select " & ifields & "
From tblQuote Where QuoteID = " & Me!QuoteID
dbs.Execute LInsert, dbFailOnError
 
Back
Top