View Full Version : Controlling Query Field Criteria from code


Mitch_____W
11-13-2001, 04:39 AM
I am trying to run an existing query from a code procedure and specifying a certain query field criteria...

For instance:

I have a query named "Expired_Annex_Query".

This query has 8 fields:
The first field is "Employee_Name"
The second field is "Employee_Annex"
The rest of the fields are 6 different expiration dates pertaining to the employee

I am trying to have an E-mail notification sent to the e-mail address associated with the annex in another table when an employee has any of the expiration date fields expired.

So I must run this query once for each annex (24 annexes), with the criteria changing each time for the "Employee_Annex" Field and an E-mail sent to the respective e-mail address associated with this annex if there are any results.

The_Doc_Man
11-13-2001, 07:01 AM
Look up the topic of Union queries.

Basically, instead of having one query with eight expiration dates, you generate a query that is the union of 8 sub-queries with one date each.

I had to do something like this for a list of servers that could have more than one function. I had 3 function fields, so what I did was this

SELECT [Server Name], [Primary Function], "Primary" as FuncClass UNION
SELECT [Server Name], [Secondary Function], "Secondary" as FuncClass UNION
SELECT [Server Name], [Teriary Function], "Tertiary" as FuncClass

The resulting query is three columns with a server name, a function, and the keywords "Primary", "Secondary", or "Tertiary". That way I can search my servers to see which ones provide a particular function using only one search operation. And of course a query can be written based on another query, so you can do a SELECT UNIQUE on the name in your second-level query to prevent sending two notices about the same person. (Or maybe you want that, who knows?)

This seems analogous to your situation and should be applicable.