Determine if record exists when updating Access database using Excel VBA Determine if record exists when updating Access database using Excel VBA database database

Determine if record exists when updating Access database using Excel VBA


Modify the insert statement to check for the existence of the key. Given what you explained, that would be

Sub Upload_Excel_to_Access()  Dim wbpath As String  wbpath = Application.ActiveWorkbook.Path  Dim con As Object '' ADODB.Connection  Set con = CreateObject("ADODB.Connection") '' New ADODB.Connection  con.Open "Provider=Microsoft.ACE.OLEDB.12.0;Data source=\\at\HRS SD Performance Data\Capacity DB.accdb;"  con.Execute _    "INSERT INTO AssigenedVol_tbl " & _    "SELECT SRC.* FROM [Excel 12.0 Xml;HDR=YES;IMEX=2;ACCDB=YES;DATABASE=C:\Users\luga\Desktop\Databasetest\DB Macro Test.xlsm].[rawdata$] " _     & " AS SRC " _     & "WHERE NOT EXISTS (select 1 from AssigenedVol_Tbl CHK WHERE CHK.ID_Unique = SRC.ID_Unique)"  con.Close  Set con = NothingEnd Sub

Note, the &'s - were done just to focus on the fact that your SRC table is being labelled, and you're checking it as CHK.