I am trying to update records, or create records if the unique ID does not exist.
The code gives me an error telling me that it would create duplicate values.
I need to include this in my code "SQL: If Exists Update Else Insert".
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 * FROM [Excel 12.0 Xml;HDR=YES;IMEX=2;ACCDB=YES;DATABASE=C:\Users\luga\Desktop\Databasetest\DB Macro Test.xlsm].[rawdata$]"
con.Close
Set con = Nothing
End Sub
The table name is "AssigenedVol_tbl"
Fields are: Process_Identifier, Login, Volume, effDate, ID_Unique (This is the primary key in the database)
"WHERE ID_Unique NOT IN(SELECT ID_Unique FROM AssigenedVol_tbl)"
. Updating is more complicated. A single UPDATE action statement won't work. I gave it a try. Apparently, solution requires opening a recordset of Access table and looping records. – Anonymous