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 TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

passing a wildcard to a query? 1

Status
Not open for further replies.

hovercraft

Technical User
Jun 19, 2006
236
US
Greetings,
This has been driving me nuts for a couple of days.
I have 2 global variables; var_lastname and var_firstname. I also have 2 functions that return the value of their respective variables (fun_lastname, fun_firstname). I then use the functions as criteria in a query.
I am using a form to accept search criteria. On it is 2 text boxes. txt_lastname, txt_firstname.
There a button to initiate the search. cmd_search.
The code on the click event is:

if (isnull(txt_lastname)=false) then
var_lastname = txt_lastname
else:
var_lastname = "like('*')"
end if
if (isnull(txt_firstname)=false) then
var_firstname = txt_firstname
else:
var_firstname = "like('*')"
end if

This works as long as I make an entry in both text boxes and I know that the problem is the "like('*')". The value of the variable is set to literally "like('*')", but I don't know how to fix it.
What I am trying to do is to have the functions pass a wildcard in the query if the text box is blank.

any advice is greatly appreciated.
Hovercraft
 
I think that you should be looking at the function, rather than the form. What is the code for the function?
 
Code in the Click event:
[tt]var_lastname = Trim(txt_lastname & "")[/tt]

Criteria cell in the query grid:
[tt]=fun_lastname() OR fun_lastname()=''[/tt]

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 
Remou,
The functions are:
function fun_lastname()
fun_lastname = var_lastname
end function
and so on...

PHV,
Thank you!! That works perfectly! Could you explain what the OR fun_lastname()='' is doing? Is that taking the place of the * ?

-Hovercraft
 
what the OR fun_lastname()='' is doing
It simply says something like: if no searched text then no criteria

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top