query issues - critera being ignored

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

All,

Found some similar posts, but didn't help my sitaution. Any help would be
appreciated. I've got the following in query design view. The function
works and pulls in a variable from combo box. The appropriate records are
selected. What is killing me is if I add an "or" conditon. Either of the
conditions work seperately but when both exist in the query, all users
dispalyed is the outcome regardless if the variable is null or has value.
Trying to avoid wrtiing multiple queries for a form. Any thoughts? Thanks in
advance.

(WORKS)

STATUS USER
---------- --------
<>"COMPLETE" GetUSER("A")

(WORKS)

STATUS USER
---------- --------
<>"COMPLETE" Like "*" (or use a blank)


(DOES NOT WORK DISPLAYS ALL, ignores GetUSER)
---------- --------
<>"COMPLETE" GetUSER("A")
<>"COMPLETE" Like "*"
 
The criteria are not being ignored. You've basically told the query to get
all records that have a value in the USER field and have a status other than
"Complete" with the second line. That includes those in the first line of
criteria

What do you expect to see? Do you want a copy of the record to appear it
the first set of criteria and another copy of the record to appear if it
meets the second set of criteria?

Example,
Get me all males in the room and get me John Spencer (a male). So, do you
expect two copies of John Spencer to be presented to you.

IF you really need a copy of the record for each set of criteria, then you
need to look at using a UNION ALL query. Union queries cannot be built
using the query grid, but must be composed in SQL view.

--
John Spencer
Access MVP 2002-2005, 2007
Center for Health Program Development and Management
University of Maryland Baltimore County
..
 
John,
I thought I would have seen all that were not complete by user if the first
line had a value for the function. If no user was present and the funciton
value was blank the query would return all that were not complete by all
users. So, your first assumption below is correct. Guess I'll have to
research union queries. I appreciate your help.

Thanks.
 
If you want all users if the function returns blank (Null or a zero length
string?) and only the specified user if the function returns a value then a
UNION query is not the answer either.

If the USER field ALWAYS has a value and is a text field then your criteria
should probably be

Field: USER
Criteria: Like IIF(GetUser("A") & "" = "", "*", GetUser("A"))

Field: Status
Criteria: <> "Complete"

--
John Spencer
Access MVP 2002-2005, 2007
Center for Health Program Development and Management
University of Maryland Baltimore County
..
 
Back
Top