T
Tom Ellison
Dear R:
I suggest you go over the logic in your WHERE statement. Remove all
the parentheses, most of which were probably added by Access anyway.
Then put in the parens needed to do this logically according to what
you have designed for it to do. I think you're going to have to move
some of the conditions around just so you can associate them together
the way you want them to work.
The amount of logic you have here is almost certainly best NOT DONE in
the design grid. Complex logic with both AND and OR can be
represented there, but the results are often unnecessarily perverted
and difficult to read.
In order to do this, you probably need to understand logic formally.
It's not a subject that's easy for many.
I expect you'd just like for someone to tell you what's wrong. In
order to do that, we would have to know exactly what you wanted it to
do.
So, I begin to guess at what you want:
WHERE DateEntered - DateRec >= [Forms]![frmMainReport]![JREntryTurn]
OR DateEntered IS NULL OR DateRec IS NULL
This is a fragment of the WHERE clause you had, making only one of the
tests. In your code, the test for DateEntered IS NULL was associated
with Date() - DateProc > [Forms]![frmMainReport]![JRProdTurn]. I say
that because the OR was between these two things. Probably it makes
no sense that way.
Also, I added a test for DateRec IS NULL, not knowing if this is
logically correct.
Now, to add another test to the above, you must first put the
statement so far inside parens before beginning to AND it with the
next piece:
WHERE (DateEntered - DateRec >= [Forms]![frmMainReport]![JREntryTurn]
OR DateEntered IS NULL OR DateRec IS NULL)
AND DateProd - DateProc >= [Forms]![frmMainReport]![JRProdTurn]
Now, can DateProd or DateProc be NULL? And, if they can, do you
include or exclude the row of results created? Assuming you include
it, the test would be:
WHERE (DateEntered - DateRec >= [Forms]![frmMainReport]![JREntryTurn]
OR DateEntered IS NULL OR DateRec IS NULL)
AND (DateProd - DateProc >= [Forms]![frmMainReport]![JRProdTurn]
OR DateProd IS NULL OR DateProc IS NULL)
Another test that may be important is to see if the user has entered a
value in JREntryTurn and in JRProdTurn. If you allow this, and want
to ignore the associated test in that case, then add this:
WHERE (DateEntered - DateRec >= [Forms]![frmMainReport]![JREntryTurn]
OR DateEntered IS NULL OR DateRec IS NULL
OR Nz([Forms]![frmMainReport]![JREntryTurn, "") = "" )
AND (DateProd - DateProc >= [Forms]![frmMainReport]![JRProdTurn]
OR DateProd IS NULL OR DateProc IS NULL
OR Nz([Forms]![frmMainReport]![JRProdTurn], "") = "" )
My guess is that your logic will have to follow making the
associations between the components being tested. AND and OR are not
commutative nor distributive (that's the precise terminology in formal
logic, which you have to understand at some level to successfully work
with this.) Rather, they are distributive (like addition and
multiplication) meaning that the order you perform the operations has
definite affect on the outcome.
Anyway, my opinion is that having a lot of extra parens added by
Access is a BIG problem here. It's not readable that way. However,
Access is going to come along and add them anyway. So take this thing
to a text editor and do the work there, saving the test in some file
for later reference, in case you need to work with it again.
Tom Ellison
Microsoft Access MVP
Ellison Enterprises - Your One Stop IT Experts
I suggest you go over the logic in your WHERE statement. Remove all
the parentheses, most of which were probably added by Access anyway.
Then put in the parens needed to do this logically according to what
you have designed for it to do. I think you're going to have to move
some of the conditions around just so you can associate them together
the way you want them to work.
The amount of logic you have here is almost certainly best NOT DONE in
the design grid. Complex logic with both AND and OR can be
represented there, but the results are often unnecessarily perverted
and difficult to read.
In order to do this, you probably need to understand logic formally.
It's not a subject that's easy for many.
I expect you'd just like for someone to tell you what's wrong. In
order to do that, we would have to know exactly what you wanted it to
do.
So, I begin to guess at what you want:
WHERE DateEntered - DateRec >= [Forms]![frmMainReport]![JREntryTurn]
OR DateEntered IS NULL OR DateRec IS NULL
This is a fragment of the WHERE clause you had, making only one of the
tests. In your code, the test for DateEntered IS NULL was associated
with Date() - DateProc > [Forms]![frmMainReport]![JRProdTurn]. I say
that because the OR was between these two things. Probably it makes
no sense that way.
Also, I added a test for DateRec IS NULL, not knowing if this is
logically correct.
Now, to add another test to the above, you must first put the
statement so far inside parens before beginning to AND it with the
next piece:
WHERE (DateEntered - DateRec >= [Forms]![frmMainReport]![JREntryTurn]
OR DateEntered IS NULL OR DateRec IS NULL)
AND DateProd - DateProc >= [Forms]![frmMainReport]![JRProdTurn]
Now, can DateProd or DateProc be NULL? And, if they can, do you
include or exclude the row of results created? Assuming you include
it, the test would be:
WHERE (DateEntered - DateRec >= [Forms]![frmMainReport]![JREntryTurn]
OR DateEntered IS NULL OR DateRec IS NULL)
AND (DateProd - DateProc >= [Forms]![frmMainReport]![JRProdTurn]
OR DateProd IS NULL OR DateProc IS NULL)
Another test that may be important is to see if the user has entered a
value in JREntryTurn and in JRProdTurn. If you allow this, and want
to ignore the associated test in that case, then add this:
WHERE (DateEntered - DateRec >= [Forms]![frmMainReport]![JREntryTurn]
OR DateEntered IS NULL OR DateRec IS NULL
OR Nz([Forms]![frmMainReport]![JREntryTurn, "") = "" )
AND (DateProd - DateProc >= [Forms]![frmMainReport]![JRProdTurn]
OR DateProd IS NULL OR DateProc IS NULL
OR Nz([Forms]![frmMainReport]![JRProdTurn], "") = "" )
My guess is that your logic will have to follow making the
associations between the components being tested. AND and OR are not
commutative nor distributive (that's the precise terminology in formal
logic, which you have to understand at some level to successfully work
with this.) Rather, they are distributive (like addition and
multiplication) meaning that the order you perform the operations has
definite affect on the outcome.
Anyway, my opinion is that having a lot of extra parens added by
Access is a BIG problem here. It's not readable that way. However,
Access is going to come along and add them anyway. So take this thing
to a text editor and do the work there, saving the test in some file
for later reference, in case you need to work with it again.
Tom Ellison
Microsoft Access MVP
Ellison Enterprises - Your One Stop IT Experts
I have 4 calculated fields in a query, and their parameters are set by
unbound controls on a form. However, the criteria don't seem to be
working - the records returned are changing every time I change the criteria
and refresh, but I see ones that definitely should not be there.
The 4 calculated fields (not necessarily named after the field names, this
is just for easy concept description) are:
- EntryTurn (# of days to enter order after it was received)
- ProcessTurn (# of days to process order after it was entered)
- ProductionTurn (# of days to make order after it was processed)
- TotalTurn (# of days from receipt of order to Production of order)
The SQL view of what I THOUGHT would work is below. Note that I included an
OR in all the calculated fields that uses Is Null and Date() minus the
PREVIOUS corresponding date field to allow for orders that had not been
Entered, Processed, or Produced yet, since turnaround still must show for
those (ie. if an order has not been processed yet, we still need to see that
it's been at least [formcontrolsvalue] days since it was Entered, etc.
SELECT ProductionData.EnteredBy, EmpList.EmpName, ProductionData.DateRec,
ProductionData.DateEntered, ProductionData.OrderPartNum,
ProductionData.PSNum, ProductionData.CustNum, CustomerList.CustName,
ProductionData.Status, OrderStatusList.Status2, ProductionData.DateProc,
ProductionData.SqFoot, ProductionData.AutoProc, ProductionData.ProcBy,
EmpList_1.EmpName, ProductionData.Notes, OrderData.OrderNum,
OrderData.DateProd, OrderData.Vendor, VendorList.VendorName, OrderData.Wall,
OrderData.Floor, OrderData.Bead, OrderData.MachineNum, OrderData.ShiftProd,
OrderData.OperatorNum, EmpList_2.EmpName, OrderData.PartnerNum,
EmpList_3.EmpName, OrderData.Inspector1Num, EmpList_4.EmpName,
OrderData.Inspector2Num, EmpList_5.EmpName, OrderData.[2ndInspector1Num],
OrderData.[2ndInspector2Num], OrderData.TurnaroundDays, OrderData.Notes,
[DateEntered]-[DateRec] AS EntryTurn, [DateProc]-[DateEntered] AS
ProcignTurn, [DateProd]-[DateProc] AS ProdTurn, [DateProd]-[DateEntered] AS
TotalTurn
FROM EmpList AS EmpList_4 RIGHT JOIN (EmpList AS EmpList_3 RIGHT JOIN
(CustomerList RIGHT JOIN (OrderStatusList RIGHT JOIN (VendorList RIGHT JOIN
(EmpList AS EmpList_5 RIGHT JOIN (EmpList AS EmpList_2 RIGHT JOIN (EmpList
AS EmpList_1 RIGHT JOIN (EmpList RIGHT JOIN (OrderData RIGHT JOIN
ProductionData ON OrderData.PSNum = ProductionData.PSNum) ON EmpList.EmpID =
ProductionData.EnteredBy) ON EmpList_1.EmpID = ProductionData.ProcBy) ON
EmpList_2.EmpID = OrderData.OperatorNum) ON EmpList_5.EmpID =
OrderData.Inspector2Num) ON VendorList.VendorID = OrderData.Vendor) ON
OrderStatusList.ID = ProductionData.Status) ON CustomerList.CustID =
ProductionData.CustNum) ON EmpList_3.EmpID = OrderData.PartnerNum) ON
EmpList_4.EmpID = OrderData.Inspector1Num
WHERE ((([DateEntered]-[DateRec])>=[Forms]![frmMainReport]![JREntryTurn])
AND (([DateProc]-[DateEntered])>=[Forms]![frmMainReport]![JRProcTurn]) AND
(([DateProd]-[DateProc])>=[Forms]![frmMainReport]![JRProdTurn]) AND
(([DateProd]-[DateEntered])>=[Forms]![frmMainReport]![JRTotalTurn])) OR
(((OrderData.DateProd) Is Null) AND
((Date()-[DateProc])>=[Forms]![frmMainReport]![JRProdTurn])) OR
(((ProductionData.DateEntered) Is Null) AND
((Date()-[DateRec])>=[Forms]![frmMainReport]![JREntryTurn])) OR
(((ProductionData.DateProc) Is Null) AND
((Date()-[DateEntered])>=[Forms]![frmMainReport]![JRProcTurn]));
However, when I'm changing these values in the form controls and
re-querying, I'm seeing records that certainly shouldn't be shown. For
instance, when I put all of them at 0 except EntryTurn (days between receipt
and entry of order), which I put at 2, let's say, I'm still seeing a bunch
of 0's in the EntryTurn of records returned.
Can someone see what's wrong just be looking at the above? I can email
someone the DB also, if you prefer to see the design grid.
Thanks for any help, I'm struggling pretty hard with this crap