Link to home
Create AccountLog in
Avatar of J.R. Sitman
J.R. SitmanFlag for United States of America

asked on

Microsoft query help

I need this query to have officename is is not null and prompt the user for the officename.  The prompt is what I don't know how to do since there is already "is not" in the criteria.

SELECT Complaints.ComplaintNo, Complaints.CaseName, Complaints.PostSiezure955Date, qryOfficerName.OfficerName, Complaints.TargetDate, Complaints.Stats2
FROM (qryOfficerName INNER JOIN Officers ON qryOfficerName.ContactID = Officers.ContactID) INNER JOIN Complaints ON Officers.ContactID = Complaints.OfficerID
WHERE (((qryOfficerName.OfficerName) Is Not Null) AND ((Complaints.Stats2) Not In ("closed")))
ORDER BY Complaints.ComplaintNo;
Avatar of aikimark
aikimark
Flag of United States of America image

If officename is not null will be in your query, the only rows will have a non-null officename value.

You might need a union query, where the first query in the list contains non-null officename rows and the second query would contain a prompted value for the officename.
Example:
SELECT Officename, Complaints.ComplaintNo, Complaints.CaseName, Complaints.PostSiezure955Date, qryOfficerName.OfficerName, Complaints.TargetDate, Complaints.Stats2
FROM (qryOfficerName INNER JOIN Officers ON qryOfficerName.ContactID = Officers.ContactID) INNER JOIN Complaints ON Officers.ContactID = Complaints.OfficerID
WHERE (((qryOfficerName.OfficerName) Is Not Null) AND ((Complaints.Stats2) Not In ("closed")))
And Officename Is Not Null
UNION ALL
SELECT [Enter Missing Office Name], Complaints.ComplaintNo, Complaints.CaseName, Complaints.PostSiezure955Date, qryOfficerName.OfficerName, Complaints.TargetDate, Complaints.Stats2
FROM (qryOfficerName INNER JOIN Officers ON qryOfficerName.ContactID = Officers.ContactID) INNER JOIN Complaints ON Officers.ContactID = Complaints.OfficerID
WHERE (((qryOfficerName.OfficerName) Is Not Null) AND ((Complaints.Stats2) Not In ("closed")))
And Officename Is Null
ORDER BY Complaints.ComplaintNo

Open in new window

Avatar of J.R. Sitman

ASKER

It prompts me for a "missing officer name"  I want it to prompt for the officer name.  See attached

User generated image
User generated image
So, which is it,  "Office name" or "Officer name"?
sorry.  officername
SELECT Complaints.ComplaintNo, Complaints.CaseName, Complaints.PostSiezure955Date, 
qryOfficerName.OfficerName, Complaints.TargetDate, Complaints.Stats2
FROM (qryOfficerName INNER JOIN Officers ON qryOfficerName.ContactID = Officers.ContactID) 
INNER JOIN Complaints ON Officers.ContactID = Complaints.OfficerID
WHERE (((qryOfficerName.OfficerName) Is Not Null) AND ((Complaints.Stats2) Not In ("closed")))
UNION ALL
SELECT Complaints.ComplaintNo, Complaints.CaseName, Complaints.PostSiezure955Date, 
[Enter Missing Office Name], Complaints.TargetDate, Complaints.Stats2
FROM (qryOfficerName INNER JOIN Officers ON qryOfficerName.ContactID = Officers.ContactID) 
INNER JOIN Complaints ON Officers.ContactID = Complaints.OfficerID
WHERE (((qryOfficerName.OfficerName) Is Null) AND ((Complaints.Stats2) Not In ("closed")))
ORDER BY Complaints.ComplaintNo

Open in new window

It's giving me all the officers, not just the name I enter.

User generated image
If you want just results for a certain Officer Name, it might be better to do this via a form with a combo box for selecting that name (or better, the key ID field of that record), and use it to return filtered results.  See my Fancy Filters sample database (attached).  Here is a screen shot of the form:
User generated imageaccarch129.zip
I need the query for a form I already designed
Take a look at the controls and code on my sample form -- you might be able to modify them to work on your form.
ASKER CERTIFIED SOLUTION
Avatar of J.R. Sitman
J.R. Sitman
Flag of United States of America image

Link to home
membership
Create an account to see this answer
Signing up is free. No credit card required.
Create Account
found my own solution outside of EE