using global variable in query design as a criteria

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

Guest

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
 
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 & ";"
 
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() & ";"
 
Back
Top