I am trying to add a record to a SQL Server DB. I am using ADO. When I try adding the record, I get the following error message:
I know the primary key is unique in this instance. I'm not sure what I'm doing wrong. I have attached the code below:Code:-2147217873: Violation of PRIMARY KEY constraint 'PK_tblClients'. Cannot insert duplicate key in object 'tblClients'.
Code:Private Sub client_IO() On Error GoTo ErrorProc If tblClients.State = 1 Then tblClients.Close End If tblClients.Open "tblClients", oConn, adOpenStatic, adLockOptimistic If tblClients.Supports(adAddNew) Then With tblClients .AddNew !cliClientID = txtClientID.Text !cliCommonName = txtCommon.Text !cliEmail = txtEmail.Text !cliAddr1 = txtAddr1.Text !cliAddr2 = txtAddr2.Text !cliCity = txtCity.Text !cliState = cmbState1.Text !cliZipCode = txtZip.Text .Update End With End If End Sub




Reply With Quote