Selecting into a variable

P

phade2blue

Hi guys and gals,

I am new to db and trying to select into a variable from a table.
I am using the code: -

DoCmd.RunSQL "SELECT """ & variable & """ = column1 " & _
"FROM table WHERE column1 =""" & another_variable &
""""

but not having a lot of look. Am doing something drastically wrong?

Any guidance is great

Cheers Phade
 
W

Wayne Morgan

What do you mean by "select INTO a variable"? What should the SQL look like
without the variable?
 
D

Dirk Goldgar

phade2blue said:
Hi guys and gals,

I am new to db and trying to select into a variable from a table.
I am using the code: -

DoCmd.RunSQL "SELECT """ & variable & """ = column1 " & _
"FROM table WHERE column1 =""" & another_variable &
""""

but not having a lot of look. Am doing something drastically wrong?

Any guidance is great

Cheers Phade

If I understand what you're trying to do, Access doesn't support that
kind of syntax. You can use the DLookup function, like this ...

YourVariable = _
DLookup("column1", "YourTable", _
"column2 = " & another_variable)

.... or you can open a recordset on the query and get the value for your
variable from one of the fields in the recordset. That's more
complicated, so I won't go into the details unless you need them.
 
B

Br@dley

phade2blue said:
Hi guys and gals,

I am new to db and trying to select into a variable from a table.
I am using the code: -

DoCmd.RunSQL "SELECT """ & variable & """ = column1 " & _
"FROM table WHERE column1 =""" & another_variable &
""""

but not having a lot of look. Am doing something drastically wrong?

Any guidance is great

Cheers Phade


You can't do that in Access. You can in SQL server stored procedures....
--
regards,

Bradley

A Christian Response
http://www.pastornet.net.au/response
 
Top