Update or Ignore if field data already exist

dan_pafc

Board Regular
Joined
Aug 16, 2007
Messages
162
Hi - Here is an extract of by code to insert new data into a table (BOData). Because the source data has the potential to contain the same data multiple times, I would like to amend my code so that if 'DataDate' and 'Avaya' already exist in the table - it updates (or ignores). Ive seen a few other examples which dont really fit my way of coding. Thanks!!

Code:
sSQL = "INSERT INTO BOData (DataDate, Avaya, Staffed, SiebelName)" & _
        "VALUES ('" & ActiveSheet.Range("A3") & "', '" & ActiveCell.Offset(0, -1).Value & "', '" & ActiveCell.Offset(0, 1).Value & "', '" & SN & "');"

'Edit the data using ADO
Set rsData = New ADODB.Recordset
rsData.Open sSQL, sConnect, _
            adOpenForwardOnly, adLockOptimistic, adCmdText
Set rsData = Nothing
 

Excel Facts

How to change case of text in Excel?
Use =UPPER() for upper case, =LOWER() for lower case, and =PROPER() for proper case. PROPER won't capitalize second c in Mccartney
this can be done without any code.

1. use a make table (or append table) query to bring in all the data
2. join this new table with the main data table, run update query to mark the existing records in the new table
3. delete marked records in new table
4. append new recs to the main data table (free of duplicates)

1 macro, 4 queries, no code.
 
Upvote 0

Forum statistics

Threads
1,221,848
Messages
6,162,415
Members
451,762
Latest member
Brainsanquine

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top