Passing values into DoCmd.RunSQL

G

Guest

Hi
having declared a variable and assigned a value to it, I am trying to pass
this value into the where clause of a RunSQL statement.

e.g

variable = "qwerty"

doCmd.RunSQL("Update tbltest Set tbltest.Column = xxxxx Where tbltestColumn2
= qwerty")

However, this does not seem to work - I need help in the correct syntax
 
B

Brendan Reynolds

WHERE tblTestColumn2 = '" & NameOfVariableHere & "'"

That's a single quote followed by a double quote after the equals sign, and
a single quote between two double quotes at the end.

I'm assuming here that we're dealing with a text field. If it was a date
field the value would need to be delimited with '#' characters instead of
the single quotes as above. If it was a numeric field, there would be no
delimiters.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top