A simple UPDATE query with INNER JOIN is causing me problems, using VB6 and DAO on an Access .MDB database.
I thought it would be simple, but whatever changes I make generate errors.
My query is:
UPDATE work
INNER JOIN emp ON work.ref = emp.ref
SET work.code1 = emp.code1
This generates run-time error 3075 Syntax error in query expression 'work.ref = emp.ref'
.
I get a similar error with:
UPDATE work w
INNER JOIN emp ON w.ref = emp.ref
SET w.code1 = emp.code1
and
UPDATE [work] w
INNER JOIN emp ON w.ref = emp.ref
SET w.code1 = emp.code1
and also if I use alias e for table emp.
I cannot use a FROM
clause, which is not supported in Access (Thanks though @MarkKram)
I have to use DAO 3.51 (old!) in VB6, which cannot easily be changed.
I have tried square brackets around the first reference to work
as in UPDATE [work]
(as I need this in a simple SELECT * FROM [work]
) as well as various combinations with and without square brackets around table names and column names. But still it fails.
Do you have any suggestions please?
Dim ws As DAO.Workspace
Dim DB As DAO.Database
Dim szSQL As String
Set ws = gWS
Set DB = gWS.OpenDatabase(WorkFile)
szSQL = "UPDATE work INNER JOIN emp ON work.ref = emp.ref SET work.code1 = emp.code1 WHERE work.trancode = 'P'"
DB.Execute szSQL
Set DB = Nothing
Set ws = Nothing