I insert data into an Access table from a row in Excel using the code here (Insert Data from Excel into Access).
I have a problem when inserting a record that is already in the table because of the same primary key value.
I want to update the record or delete the record and enter a new one with the same key.
Dim Connect As ADODB.Connection
Set Connect = New ADODB.Connection
Connect.Open "Provider=Microsoft.Ace.OLEDB.12.0;Data Source=C:\Users\ExcelFileName.xlsm;Extended Properties=Excel 8.0;" & "Persist Security Info=False"
Connect.Execute "INSERT INTO tbl_TCM_MAA_Data IN 'C:\DataBaseFileName.accdb' SELECT * FROM [SheetName$A2:O2]"
Connect.Close
Set Connect = Nothing
selectquery to see if the id already exists, then run either an update or an insert depending on the results - Tim Williams