Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Ignore critera if Null 2

Status
Not open for further replies.

onefootout

Technical User
Oct 23, 2007
42
US
Hi All,

I'm just getting back into sql/access after a 5 year hiatus. I feel like I should be able to solve this problem by myself, but I'm stymied.

I have a query being run by values entered in a form, like so:

SELECT Txns.InvoiceNumber, Txns.SkillCode, Txns.EmpName
FROM Txns
WHERE (((Txns.InvoiceNumber)=[forms]![_skillcodechange]![invnum]) AND ((Txns.EmpName)=[forms]![_skillcodechange]![empname]));

I need it to do something like this:

SELECT Txns.InvoiceNumber, Txns.SkillCode, Txns.EmpName
FROM Txns

WHERE

-->these two fields return values

(((Txns.InvoiceNumber)=[forms]![_skillcodechange]![invnum]) AND
((Txns.EmpName)=[forms]![_skillcodechange]![empname]));

-->or if there's nothing in [empname], ignore that input and just query by the value in [invnum]

I thought about using the Nz() function, but I'm not sure if that's the right solution. I don't want to return a value if there's no match, I want to ignore it.

Thanks so much!
 
Try something like:

Code:
SELECT Txns.InvoiceNumber, Txns.SkillCode, Txns.EmpName
FROM Txns
WHERE (Txns.InvoiceNumber=[forms]![_skillcodechange]![invnum] OR [forms]![_skillcodechange]![invnum] IS Null) AND (Txns.EmpName=[forms]![_skillcodechange]![empname] OR [forms]![_skillcodechange]![empname] is Null);


Duane MS Access MVP
[green]Ask a great question, get a great answer.[/green] [red]Ask a vague question, get a vague answer.[/red]
[green]Find out how to get great answers faq219-2884.[/green]
 
SELECT Txns.InvoiceNumber, Txns.SkillCode, Txns.EmpName
FROM Txns
WHERE (Txns.InvoiceNumber=[forms]![_skillcodechange]![invnum] OR [forms]![_skillcodechange]![invnum] Is Null)
AND (Txns.EmpName=[forms]![_skillcodechange]![empname] OR [forms]![_skillcodechange]![empname] Is Null);

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
dhookom & PHV,

Works like a charm. Thanks a lot.



 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top