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

How do I pass no criteria to Query through my function? 1

Status
Not open for further replies.

ThinWhiteDude

Technical User
Sep 21, 2004
97
US
Hopefully, this is the right forum to post this question to.

With the help of several posts on the forum, I have been able to set a variable as criteria in a select query via a form. I used the visual QBE to create this query, and use a function to pull in the variable for the criteria, so I didn’t write the SQL for it.

Here’s the project background:
I have set up a form for users to click a button to run a report for their department. A variable is set in the click event of each department button to hold the string name of their department(strLocation). I have a function that then sets a (public) variable with this department name. Like this:

From the form:
Code:
    SetLoc (strLocation)

Here are the functions:
Code:
Function SetLoc(strLocation As String)
    If strLocation <> "All Depts" Then
        gstrLoc = strLocation
    Else
    End If
End Function
For the Department criteria in the query, I call the GetLoc function.
Code:
Function GetLoc() As String
    GetLoc = gstrLoc
End Function

Everything works just fine. However, I need to be able to allow for all records to be pulled in when they click on the “All Depts” button. So, in effect, no criteria. I am stuck on how to pass that on to the function, or set it in the function if necessary.
So. . .
Using this function, how can I pass the equivalent of no criteria to the query?

As always, any help will be much appreciated
TWD
 
Change your query selection criter from:
GetLoc()
to:
Like GetLoc()

Then where you want ALL, set variable gstrLoc to "*"

"Hmmm, it worked when I tested it....
 
Trevil,

Thank you so Much!!!!

And have a star for helping me. . . Yes, I did test it and it works like a charm.

Hope your day is as nice as mine is now going to be!
TWD
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top