0

Writing an sql string in vba and getting syntax error for a missing operator. I thought the error was with the inner joins so I tried taking them out but still same error.

Here is the query string:

sql1 = "SELECT WorkOrder.ProjectID, tref_dep.department, live_project.project_codename " _
     & "FROM WorkOrder " _
     & "INNER JOIN tlive_project " _
     & "ON tlive_project.project_id = WorkOrder.ProjectID " _
     & "INNER JOIN tref_dep " _
     & "ON tref_dep.dep_id = WorkOrder.ToDepartment " _
     & "WHERE WorkOrder.ToDepartment = " & rs1!wo_depart_id & " AND WorkOrder.ProjectID = " & rs1!proj_id _
     & " CONTAINS(WorkOrder.WorkOrderDescription, 'TimeForce Upload,') " _
     & "LIMIT 1"

I am probably missing something simple but any help is greatly appreciated!

2 Answers 2

1

You have forgotten a logic operator before CONTAINS(..) :

 & "WHERE WorkOrder.ToDepartment = " & rs1!wo_depart_id & " AND WorkOrder.ProjectID = " & rs1!proj_id _
 & "AND CONTAINS(WorkOrder.WorkOrderDescription, 'TimeForce Upload,') " _
 & "LIMIT 1"
Sign up to request clarification or add additional context in comments.

3 Comments

Thanks @notulysses for the quick reply. I should have been more specific in my post but, rs1!wo_depart_id and rs1!proj_id are integers so I don't think I need the single quotes around them.
@Rob : have you succeeded?
Thanks for your help. Found out in VBA if you have 2 or more JOIN clauses you have to put a parenthesis around each individual clause. That was where I was getting my error. I have updated with answer
0

VBA requires parenthesis for 2 or more JOIN clauses.

sql1 = "SELECT WorkOrder.ProjectID, tref_dep.department, live_project.project_codename " _
 & "FROM (WorkOrder " _
 & "INNER JOIN tlive_project " _
 & "ON tlive_project.project_id = WorkOrder.ProjectID) " _
 & "INNER JOIN tref_dep " _
 & "ON tref_dep.dep_id = WorkOrder.ToDepartment " _
 & "WHERE WorkOrder.ToDepartment = " & rs1!wo_depart_id & " AND WorkOrder.ProjectID = " & rs1!proj_id _
 & " CONTAINS(WorkOrder.WorkOrderDescription, 'TimeForce Upload,') " _
 & "LIMIT 1"

Comments

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.