Skip to content
Advertisement

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.

Advertisement

Answer

I think you were going for this:

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

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

User contributions licensed under: CC BY-SA
7 People found this is helpful
Advertisement