using global variable in query design as a criteria

D

dimwit

i have a variable declared in a module i want to use it as a criteria in my query how can i incorporate it? help please
 
D

Dan

i have a variable declared in a module i want to use it as a criteria in my query how can i incorporate it? help please

Let us say your variable is called strCity, that is a string variable.
And you want to search on the City field of table tblCities:

strSQL = "SELECT * from tblCities WHERE " & strCity & ";"
 
R

Rick Brandt

Dan said:
I don't think it is possible to reference a code variable from Query
Design Mode...

No, but you can use custom functions so all you need is a wrapper function
whose only purpose is to return the value of the variable.

Function GetStrCity() as String
GetStrCity = strCity
End Function

strSQL = "SELECT * from tblCities WHERE " & GetStrCity() & ";"
 

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