Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Wanet Telecoms Ltd on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Code in Querys

Status
Not open for further replies.

fabby1

Technical User
Mar 9, 2004
206
GB
Hi

I have a global variable G_LOCATION that is either set to

"Like BES" or
"NOT Like BES"


I then have a wrapper function

Code:
Public Function LOCATION() As String
   LOCATION = G_Location
End Function

This is called from with in a query

e.g.

Field: Location
Table: dbo_Master1

Criteria: Location()

My Wuester is:

Is it possible to set the Criteria using my wrapper function e.g. LIKE BES

Or will I have to hard code it into the Query e.g. Like Location()


Thanks

Phil
 
You can call the function to get your criteria, if thats what you are asking.

ChaZ
 
You may take a look at the Eval function.
Create a Public function in a standard code module, like this:
Public Function myEval(str2Eval As String)
myEval = Eval(str2Eval)
End Function
Then, provided that G_Location is "Like [highlight]'[/highlight]BES[highlight]'[/highlight]" or "NOT Like [highlight]'[/highlight]BES[highlight]'[/highlight]", you may try something like this in your sql code:
WHERE myEval("'" & dbo_Master1.Location & "'" & LOCATION())

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ222-2244
 
Yes Fabby it is, but at present, I don't see the point.

you could just do, Criteria = "G_Location".

I'm assuming, you used the above syntax, just to explain?

Proper is,

"SELECT Location FROM [dbo_Master1] WHERE Location " & G_Location

...but, G_Location as is, will produce a syntax error, if Bes, is not surrounded with brackets.

G_Location = "Not Like " & chr(34 & "Bes" & chr(34).

If these are the only options, Like or Not like, then you could hard code the value, & toggle G_Location, between "Not" & "".

G_Location = "Not"
or
G_Location = ""

"SELECT Location FROM [dbo_Master1] WHERE Location " & G_Location & " Like 'Bes'"

Same diff???

Hope this helps, good luck!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top