Reputation: 73
I'm trying to Update column1 in table1 with values from column2 from table2 with a criteria in table2. This is very confusing so here is my SQL code, maybe then you understand what I mean...
Private Sub Button_Click()
Dim strSQL As String
strSQL = "UPDATE table1 SET column1 = table2.column2 WHERE table2.ID = 1"
CurrentDb.Execute strSQL
End Sub
This code isn't working as expected, so I need your help...
Thanks in advance!
Upvotes: 2
Views: 11958
Reputation: 27634
You need to join your tables, and then you can set the value:
UPDATE table1
INNER JOIN table2 ON table1.ID = table2.ID
SET table1.column1 = table2.column2
WHERE table2.ID = 1 -- not sure if you actually want to keep this criterium
Upvotes: 6