Add to existing report query

OK I've looked at this too long... I have a menu that the user selects a report type and then opens a report based on that..... Its working great but I wanted to alter is slightly with one query.  As its stands now, it will pull a "daily" report which concists of orders older than 9 days old with a certain order status and if the Outlab and office are not equal to a criteria.  What I would like to alter is keeping it all the same but if the Outlab is MAH, instead of excluding it, I would like to include it in the report but not if more than 9 days from the DOS but 28 days from the DOS.  

Here is the code I"m using now that is working but excludes the MAH lab:

DoCmd.OpenReport "rGeneral", PrintOption, , "((IIf (IsNull([DatePtUpdate]),Now()-[DOS]>9, Now()-[DatePtUpdate]>9) And (tMain.Office) <> ""EWS"" And ((tMain.Outlab) <> ""MAH"" or isNull([tMain.Outlab])) and (tMain.Status) Not In ('Ready for PU','Cancelled')))"

Can someone assist with the code?  Just to sumarize, I'm looking to keep the criteria the same as is, just to add MAH labs not to be excluded but have MAH orders 28 days old (using the same logic)  I hope I am being clear.

I have this working but would like to "clean" it up a bit.

DoCmd.OpenReport "rGeneral", PrintOption, , "((IIf (IsNull([DatePtUpdate]),Now()-[DOS]>9, Now()-[DatePtUpdate]>9) And (tMain.Office) <> ""EWS"" And ((tMain.Outlab) <> ""MAH"" or isNull([tMain.Outlab])) and (tMain.Status) Not In ('Ready for PU','Cancelled') OR ((IIf (IsNull([DatePtUpdate]),Now()-[DOS]>28, Now()-[DatePtUpdate]>28) And (tMain.Office) <> ""EWS"" And ((tMain.Outlab) = ""MAH"" or isNull([tMain.Outlab])) and (tMain.Status) Not In ('Ready for PU','Cancelled')))"

Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Jeffrey CoachmanMIS LiasonCommented:
Then you must carefully consider your "nesting"

FWIW, if my report criteria was this complex I would consider building the SQL for the report in code...
...or building this as a Filter.

But even before that, I would create a query that returns what I wanted first, *then* creating the report open code should be easy after that.


Dale FyeOwner, Developing Solutions LLCCommented:
Let me make sure I understand, the basic recordsource for your report works fine, and returns all records.  

What you want to do is change the WhereCriteria of the OpenReport method from your first line to what is in the 2nd.  It looks like, that is working too, but you just want to "clean that criteria expression up a bit", is that correct?
Dale FyeOwner, Developing Solutions LLCCommented:
When I disected your second criteria string, the only difference I fould was inside the IIF clause.  The first one reads:

IIf (IsNull([DatePtUpdate]),Now()-[DOS]>9, Now()-[DatePtUpdate]>9)

The second reads:

IIf (IsNull([DatePtUpdate]),Now()-[DOS]>28, Now()-[DatePtUpdate]>28)

but the first is just a subset of the second.  Personally, I would get rid of the IIF clause and use:

Now() - NZ([DatePtUpdate], [DOS]) > 28

I would also replace:

((tMain.Outlab) = ""MAH"" or isNull([tMain.Outlab]))


(NZ(tMain.Outlab, ""MAH"") = ""MAH"")

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Protecting & Securing Your Critical Data

Considering 93 percent of companies file for bankruptcy within 12 months of a disaster that blocked access to their data for 10 days or more, planning for the worst is just smart business. Learn how Acronis Backup integrates security at every stage

thandelAuthor Commented:
Thanks to make sure I understand can you provide a completed final line of code?
Qlemo"Batchelor", Developer and EE Topic AdvisorCommented:
I've requested that this question be deleted for the following reason:

This question has been classified as abandoned and is closed as part of the Cleanup Program. See the recommendation for more details.
Jeffrey CoachmanMIS LiasonCommented:
Points to fyed
thandelAuthor Commented:
Yes please points to Fyed
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Query Syntax

From novice to tech pro — start learning today.