Variables in a WHERE Clause

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

How do I pass a variable into the WHERE Clause of a SELECT Statement? I have the follwoing line of code

.Open "SELECT * FROM ScratchTable WHERE Stock_Sym = 'FetchStr'", connFCY, adOpenKeyset, adLockOptimistic

All of this works correctly, except the variable FetchStr, which resolves to a stock symbol, isn't getting passed correctly. Enclosed in single quotes, as above, makes the variable treated as a literal (the WHERE looks for FetchStr in the Stock_Sym field rather than looking for the stock symbol contained in the variable FetchStr). Without the single quotes, and I get a missing parameter error

Any help would be much appreciated

Eric Hines
 
How do I pass a variable into the WHERE Clause of a SELECT Statement?
I have the follwoing line of code:
.Open "SELECT * FROM ScratchTable WHERE Stock_Sym = 'FetchStr'",
connFCY, adOpenKeyset, adLockOptimistic
All of this works correctly, except the variable FetchStr, which resolves to a stock symbol, isn't getting passed correctly.
Enclosed in single quotes, as above, makes the variable treated as a
literal (the WHERE looks for FetchStr in the Stock_Sym field rather
than looking for the stock symbol contained in the variable FetchStr).
Without the single quotes, and I get a missing parameter error.
Any help would be much appreciated.

Eric Hines

Eric,
Try:
.... WHERE Stock_Sym = ' " & FetchStr & " ' ", etc.
(I've added spaces between the quotes for clarity.
Remove the spaces.
 
Fred

Works like a champ. Thanks

Eri

----- (e-mail address removed) wrote: ----

On Fri, 16 Jan 2004 21:41:05 -0800, "E Hines" <[email protected]
wrote
How do I pass a variable into the WHERE Clause of a SELECT Statement?
I have the follwoing line of codeEnclosed in single quotes, as above, makes the variable treated as
literal (the WHERE looks for FetchStr in the Stock_Sym field rathe
than looking for the stock symbol contained in the variable FetchStr)
Without the single quotes, and I get a missing parameter error
Eric
Try
.... WHERE Stock_Sym = ' " & FetchStr & " ' ", etc
(I've added spaces between the quotes for clarity.
Remove the spaces
-
Fre

Please reply only to this newsgroup
I do not reply to personal e-mail
 
Back
Top