0

I'm trying to update the table with inner join using VBA in MS Access but I've tested the SQL Update statement in SQL Server Management Studio and it's working. I'm getting an error as a result, see below.

Appreciate any help.

SQL = "Update A set A.RevBillCtrl = 8 from dbo_tblMain A inner join dbo_tblPlateNo as B ON B.PNC = A.PLC inner join dbo_tblSubcons as C on B.SCC = C.SCC "

enter image description here

2
  • What data type is A.RevBillCtrl? Commented Mar 2, 2017 at 3:21
  • Data type of A.RevBillCtrl is integer. Commented Mar 2, 2017 at 3:26

2 Answers 2

1

In Access the Update with joins has a different syntax comparing to SQL Server. The correct syntax will be:

Update dbo_tblMain AS A 
inner join dbo_tblPlateNo as B on B.PNC = A.PLC 
inner join dbo_tblSubcons as C on B.SCC = C.SCC
set A.RevBillCtrl = 8 

BTW, earlier Access versions did not like the INNER JOINS that follow one after another. They used a nested joins syntax:

Update dbo_tblMain AS A 
inner join (dbo_tblPlateNo as B
  inner join (dbo_tblSubcons as C 
  on B.SCC = C.SCC)
on B.PNC = A.PLC)
set A.RevBillCtrl = 8 
Sign up to request clarification or add additional context in comments.

6 Comments

I have tried below query but i'm getting an error. RunTime Error '3075' : Syntax Error (missing operator) in query expression 'B.PNC = A.PLC inner join dbo_tblSubcons AS C ON B.SCC = C.SC'. Update dbo_tblMain A inner join dbo_tblPlateNo as B ON B.PNC = A.PLC inner join dbo_tblSubcons as C on B.SCC = C.SCC set A.RevBillCtrl = 8
try one with the nested joins
sorry, messed the nested joins syntax. try again
The bottom block was the same as the top one, so I edited the bottom one to a nested join, but then realized there were parentheses.. and I don't know whether parentheses are mandatory in Access, nor where they're supposed to be going - so I edited it further, but I think I should have just left it alone... feel free to rollback or fix or whatever.
@Mat'sMug: yes, Access's craziness around their joins makes everyone crazy
|
0

The idea basically is that you have to do the JOINs in a nested way. See below correct one.

Sql = "UPDATE dbo_tblMain
      INNER JOIN (dbo_tblPlateNo 
       INNER JOIN dbo_tblSubCons 
       ON (dbo_tblPlateNo.SCC = dbo_tblSubCons.SCC)) 
      ON (dbo_tblMain.PLC = dbo_tblPlateNo.PNC) 
      SET dbo_tblMain.RevBillCtrl = 8"

1 Comment

Test your queries by writing them as an actual query not in vba. Not sure u need vba here. If you just use query desinger to drag the joins, access will handle the syntax

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.