Using a variable in a select statement

P

Pat Turner

I am trying to do pass a variable to a select statement.
A variable which I would declare in a dim statement

Select * from table WHERE field1 = (variable)
 
G

Gerald Stanley

If the variable is a number, then the format is
"Select * from table WHERE field1 = " & (variable)
If it is a string, the format is
"Select * from table WHERE field1 = '" & (variable) & "'"
If it is a date, the format is
"Select * from table WHERE field1 = #" & format((variable),
"mm/dd/yyyy") & "#"

Hope This Helps
Gerald Stanley MCSD
 

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