Hey everyone! I’m working on a project where I’m using Excel as a front-end for an Access database to manage shifts and activities. I’ve got the data import working fine, but now I’m stuck on how to update existing records in the Access table.
Here’s a snippet of my current VBA code for importing data:
Sub ImportNewData()
Dim db As New ADODB.Connection
Dim sql As String
Dim dataSheet As Worksheet
Set dataSheet = Worksheets("Schedule")
For row = 2 To dataSheet.UsedRange.Rows.Count
For col = 2 To dataSheet.UsedRange.Columns.Count
date = dataSheet.Range("A1").Value
activity = dataSheet.Cells(1, col).Value
employee = dataSheet.Cells(row, 1).Value
slot = dataSheet.Cells(row, col).Value
If slot <> "" Then
sql = "INSERT INTO schedule_table (Date, Employee, Slot, Activity) VALUES ('" & date & "', '" & employee & "', '" & slot & "', '" & activity & "')"
db.Execute sql
End If
Next col
Next row
End Sub
Any tips on how I can modify this to update existing records instead of just inserting new ones? Thanks in advance for your help!