1

I need a little help developing my SQL query. My goal is to remove an entry. My condition is two tables away. I've gotten this far but I can't seem to find where the other mistake

con.Execute "DELETE FROM Expenses INNER JOIN Agreements ON Agreements.AgreementsID = 
             Expenses.AgreementID AND INNER JOIN Audits 
             ON Audits.AuditID = Agreements.AuditID WHERE Audits.Share = True"

I'm using access 2007 and my con variable is

con.Open _
"Driver={Microsoft Access Driver (*.mdb, *.accdb)};" & _
"Dbq=" & Loc & ";"
2
  • Can you run that sql directly, ie without using vba? You might want to test it with a select query first. Commented Dec 23, 2014 at 17:45
  • No still breaks. Same error Commented Dec 23, 2014 at 18:18

1 Answer 1

1

Try This, You are using AND before INNER JOIN, remove that only.

DELETE DISTINCTROW Expenses.* 
  FROM Expenses 
           INNER JOIN Agreements ON Agreements.AgreementsID = Expenses.AgreementID 
           INNER JOIN Audits ON Audits.AuditID = Agreements.AuditID 
  WHERE Audits.Share = True

[EDIT Query]

  DELETE Expenses.* 
  FROM Expenses 
  WHERE Expenses.AgreementID IN (
                         SELECT Agreements.AgreementID FROM Agreements 
                         INNER JOIN Audits ON Audits.AuditID = Agreements.AuditID
                         WHERE Audits.Share = True
                        )

OP get error:- Too few parameters Expected 2.

To handle this, This error may be obtained because the any column names being selected have special characters in it. If there are special characters in the column names of the database, the name should be surrounded with brackets in the SQL query. So if you have any column name which have special char value , then try [ColumnName]

Sign up to request clarification or add additional context in comments.

11 Comments

Now the error I'm getting is [Microsoft][ODBC Microsoft Access Driver] Syntax error (missing operator) in the query expression 'Agreements.AgreementID = Expenses.AgreementID INNER JOIN Audits.AuditID = Agreements.AuditI',
@see one more time, I added DISTINCTROW in query
what the Audits.Share conatins, if these are bool column then use 0 or 1 instead of True/ False
Try Edit Section Query
Too few parameters Expected 2
|

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.