0

Can you please help me? I was trying to figure it out for about 2 hours but I still have some error in the syntax.

I have the following code with String variables which I need to pass into the SQL query in VBA script, but I am keep getting some syntax errors.

DoCmd.RunSQL "Delete * From " '" & [tableName] & "' & " Where (" '" & [tableFieldName] & "' & " = " & '" & [tableRecord] & "')"

Thank you very much for some advice.

1
  • 1
    First apostrophe is outside of text and thereby treated as comment. Of course if it would be inside of the string, then it would give syntax error also - table and field names should not be written inside apostrophes. And, if it is real SQL, then delete syntax doesn't include asterisk (*) - what kind of DBMS you are using? Commented Sep 10, 2020 at 10:19

1 Answer 1

1

I think you were going for this:

DoCmd.RunSQL "Delete From [" & TableName & "] Where [" & tableFieldName & "] = '" & tableRecord & "'"

Where I assume TableName, tableFieldName and tableRecord are variables??

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

3 Comments

Thank you very much for your help. TableName, tableFieldName and tableRecord are indeed variables, however I'm still getting the syntax error. Now it is the 3450 error.
Actually I changed my answer it wasn't quite right, I have no surrounded the TableName and the tableFieldName with square brackets []
Also are you using Access here and not Excel?

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.