M_V
M_V

Reputation: 105

VBA 3131 error in SQL using variables in query

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.

Upvotes: 0

Views: 71

Answers (1)

jamheadart
jamheadart

Reputation: 5343

I think you were going for this:

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

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

Upvotes: 1

Related Questions