|
|
Subject:
Access Query
Category: Computers > Programming Asked by: bselltiz-ga List Price: $10.00 |
Posted:
20 Dec 2002 23:18 PST
Expires: 19 Jan 2003 23:18 PST Question ID: 132082 |
I have a query that needs to have a string criteria (Employee) supplied before it returns its results. I also have a form with a combo box of employees, when an employee is chosen I have code write the chosen value to a temp table. Only one employee can be specified at a time. In the Employee field within the query I have a DLookup function pointing the temporary table holding the value of the employee chosen. Please note that the Employee is not actually returned in the query's results as it is grouped....actually it's a pivot table but I doubt that is really relevant. Anyway, This all works fine and dandy. The problem arises when there is no employee chosen. Instead of showing no records I want to show records for ALL employees. No matter what I do I can not get the criteria to evaluate correctly when there is no value in the temp table. I have tried IIFs to evaluate to IN(Select Employee from Employee) if the value in the temp table is NULL. I have even tried to use Like(*) when the value in the table is null, but nothing works. If I put either one of those two methods in without the IIF then the query runs fine. So I guess what I really need to know is how to use conditional criteria in a query. | |
| |
|
|
Subject:
Re: Access Query
Answered By: hammer-ga on 21 Dec 2002 13:06 PST Rated: |
You need to add "OR MyLookedUpValue Is Null" to your criteria. The exact syntax depends on what you currently have. By the way, you may be doing this the hard way. There are ways to pass a value to a query without resorting to temporary tables. I recommend you read the Help files on Parameter queries. Also, if you run the query while the form with the combo box is still open, you can use the value directly as your criteria. Take a look at this example of doing this using the value selected on the form as the parameter, rather than doing a DLookup: http://www.mvps.org/access/queries/qry0001.htm This is an excellect Access FAQ. You may want to take a look around it while you're there. http://www.mvps.org/access/ The logic behind this solution is simple. When you use criteria, Access looks at each record to see if it matches. The answer is returned as True or False. If the answer is True, the record is added to your recordset. If the criteria is: EmployeeName = "John Doe" then any record where "John Doe" appears in EmployeeName returns True. By saying: (EmployeeName = MyLookedUpValue) OR (MyLookedUpValue Is Null) you tell Access to return True if *either* expression is True. If your value is Null, then the second expression is *always* True and you get all the records, regardless of what the Employee Name is. If your value is not Null, then the second expression is always False and your value must match the EmployeeName to return True. Good luck with your Access project! - Hammer | |
| |
| |
|
bselltiz-ga
rated this answer:
and gave an additional tip of:
$5.00
Was very quick to answer and had all the right information. Hammer explained very cleary what I needed to know. He also gave me several other options to try as well as links to more information. This researcher is tops! |
|
There are no comments at this time. |
If you feel that you have found inappropriate content, please let us know by emailing us at answers-support@google.com with the question ID listed above. Thank you. |
Search Google Answers for |
Google Home - Answers FAQ - Terms of Service - Privacy Policy |