|
Question : How can I set a variable equal to a value returned from an SQL SELECT statement
|
|
How can I set a variable equal to a value returned from an SQL SELECT statement in MS Access (I am using MS Access 97)
I have a Table1 with 5 entries.
ID Animal 1 cat 2 dog 3 mouse 4 cow 5 horse
If I wrote an SELECT Table1.Animal from Table1 WHERE Table1.ID = 1 It would return cat.
I want to create a variable and have it be assigned to the value "cat" the value returned by my select statement when Table1.ID = 1, and have the variable be "dog" when Table1.ID = 2, etc. Here is what I was trying to do. Thanks, Terri
Dim intx As Integer Dim myvar As Variable
For intx = 1 To 5
myvar = "SELECT Table1.Animal from Table1 WHERE Table1.ID = " & intx MsgBox "intx is " & intx & " and myvar is " & myvar
Next intx
|
|
Answer : How can I set a variable equal to a value returned from an SQL SELECT statement
|
|
you can use dlookup to get values like that:
myvar = Dlookup("[Animal]","Table1","[ID] = " & intx)
|
|
|
|