Global Variable in a query criteria...

Steiny386

New member
Local time
Today, 08:40
Joined
Sep 4, 2003
Messages
5
Hello...first post, so bare with me:)

I am trying to use a global variable in the criteria of a query. Actually I want to use global variables for many fields in the querie's criteria...for example:

Field: JobName, Criteria: =X-73845 (which I get from a combo and set a global variable equal to)

Field: JobStartTime, Criteria: =6/12/2003 8:42 PM (as date)...(which I get from a combo and set a global variable equal to)

Field: PartsRan, Criteria: <500 (which I get from a combo and set a global variable equal to)

In other words I am using strings, integers and dates....getting them from a combo box and setting global variables equal to them...so I can use them later.

I don't know how to use the global variable in my query...I can use them in my forms, just not my queries.
-----------------------------------------------------------
Next thing is how do I basically not look for a criteria if one of the combo boxes is left empty. For example: If I allow them to query by operator but they do not want to narrow it down that much...how do I NOT query according to that criteria if my global variable is basically a null now?

Currently I am deleting my query and creating a new query with an SQL statement using the combo info for my where portion of the SQL.

Am I stuck doing it the way I am or is there another way?...There's always two ways to skin a cat...Right?
:)

Thank you for your time in advance!
 
Make a public function:

Code:
Public Function MyOperator() As String
    MyOperator = myGlobalVariable
End Function

and put the function in the criteria.
 
Many questions in there....

Regarding what to do about storing values for later. If you don't want to keep the form open until the query needs to be run, you could store the values in a temporary table also. How much later are you talking about when you say you want to use the values "later"?

Ther are many ways to handle an empty combo box, depending on how your query is set up. One technique is discussed here: Query to return all record when nothing is entered . If you're using SQL to build a WHERE clause though, it's easier than that. Just skip that field.

Give us some more detail and we can help you out.
 
Mile-O-Phile:
Thanks for the function suggestion...it worked just like it's supposed to!


dcx693:
After digging into it a little I followed your link and got some good stuff on previous threads. I have decided not to use the Global variables because of Null issues in the combo boxes....but I will be using your linked info by putting the combo box value in the criteria and following it with an or [comboboxvalue] is null. This worked great to get around Null values in my combos.

Thank you guys for your speedy responses!
 

Users who are viewing this thread

Back
Top Bottom