R
rgrantz
I retitled this for future searches, as the problem and solution seem to be
getting away from the original post title. OK, I've been trying to apply
query logic using the SQL text editor rather than the query grid, as it
seems Access adds a whole bunch of opening and closing parenthesis and the
like, which messes up the order of criteria checked, etc. All criteria are
provided via unbound controls on the form. I have the following as the
Where Clause (my own comments for this post are preceded by the typical '
comment statement in VBA), and Access returns a "query is too complex"
message:
WHERE
(
(ProductionData.EnteredBy =
[Forms]![frmMainReport]![JREnteredBy])
OR
([Forms]![frmMainReport]![JREnteredBy] Is Null)
)
' the above returns records matching control value or all records if control
is null
AND
(
(ProductionData.DesBy =
[Forms]![frmMainReport]![JRDesBy])
OR
([Forms]![frmMainReport]![JRDesBy] Is Null)
)
' the above returns records matching control value or all records if control
is null
AND
(
(ProductionData.CustNum =
[Forms]![frmMainReport]![JRCustNum])
OR
([Forms]![frmMainReport]![JRCustNum] Is Null)
)
' the above returns records matching control value or all records if control
is null
AND
(
(([DateEntered]-[DateRec]) >=
[Forms]![frmMainReport]![JREntryTurn])
OR
(([DateEntered] Is Null) and (Date()-[DateRec]) >=
[Forms]![frmMainReport]![JREntryTurn])
)
' the above returns all records where the number of days between DateRec and
DateEntered is more than or equal to the number put in the JREntryTurn
field. ALSO, if for any record the DateEntered field has not been entered
yet, it will show records where the number of days between today's date and
DateRec is more than or equal to the JREntryTurn field value (I don't need
to check for null value with this). This is because turnaround for the
entry of orders received should still be shown for orders that are received
but haven't been entered yet. The same principal applies to the remaining
criteria below, which are all about the turnaround time between one phase of
the order process and the next (except the last one, which is total
turnaround from receipt to production).
AND
(
(([DateDes]-[DateEntered]) >=
[Forms]![frmMainReport]![JRDesTurn])
OR
(([DateDes] Is Null) and (Date()-[DateEntered]) >=
[Forms]![frmMainReport]![JRDesTurn])
)
AND
(
(([DateProd]-[DateDes]) >=
[Forms]![frmMainReport]![JRProdTurn])
OR
(([DateProd] Is Null) and (Date()-[DateDes]) >=
[Forms]![frmMainReport]![JRProdTurn])
)
AND
(
(([DateProd]-[DateEntered]) >=
[Forms]![frmMainReport]![JRTotalTurn])
OR
(([DateProd] Is Null) and (Date()-[DateRec]) >=
[Forms]![frmMainReport]![JRTotalTurn])
)
Now, the query can't be opened in SQL view (text too long to be edited), but
I DID notice that before I added a couple additional criteria, Access did
replace the original SQL that I typed in myself with a HUGE increase in text
after the query was run using the form (ie. I typed in the SQL string seen
above, saved and closed the query, opened the form whose recordsource is
this query, changed a fiew criteria and refreshed, and then came back to the
query and opened it in SQL view, and saw that there was at least 5 times the
amount of text and parenthetical phrases as what I had originally typed). I
don't know if Access automatically changing the logic to longer strings is
part of the problem or not.
I can make this DB available for DL if someone wants to see this behaviour
duplicated.
Can anyone tell me a way to accomplish the SQL string above without a "too
complex" error?
getting away from the original post title. OK, I've been trying to apply
query logic using the SQL text editor rather than the query grid, as it
seems Access adds a whole bunch of opening and closing parenthesis and the
like, which messes up the order of criteria checked, etc. All criteria are
provided via unbound controls on the form. I have the following as the
Where Clause (my own comments for this post are preceded by the typical '
comment statement in VBA), and Access returns a "query is too complex"
message:
WHERE
(
(ProductionData.EnteredBy =
[Forms]![frmMainReport]![JREnteredBy])
OR
([Forms]![frmMainReport]![JREnteredBy] Is Null)
)
' the above returns records matching control value or all records if control
is null
AND
(
(ProductionData.DesBy =
[Forms]![frmMainReport]![JRDesBy])
OR
([Forms]![frmMainReport]![JRDesBy] Is Null)
)
' the above returns records matching control value or all records if control
is null
AND
(
(ProductionData.CustNum =
[Forms]![frmMainReport]![JRCustNum])
OR
([Forms]![frmMainReport]![JRCustNum] Is Null)
)
' the above returns records matching control value or all records if control
is null
AND
(
(([DateEntered]-[DateRec]) >=
[Forms]![frmMainReport]![JREntryTurn])
OR
(([DateEntered] Is Null) and (Date()-[DateRec]) >=
[Forms]![frmMainReport]![JREntryTurn])
)
' the above returns all records where the number of days between DateRec and
DateEntered is more than or equal to the number put in the JREntryTurn
field. ALSO, if for any record the DateEntered field has not been entered
yet, it will show records where the number of days between today's date and
DateRec is more than or equal to the JREntryTurn field value (I don't need
to check for null value with this). This is because turnaround for the
entry of orders received should still be shown for orders that are received
but haven't been entered yet. The same principal applies to the remaining
criteria below, which are all about the turnaround time between one phase of
the order process and the next (except the last one, which is total
turnaround from receipt to production).
AND
(
(([DateDes]-[DateEntered]) >=
[Forms]![frmMainReport]![JRDesTurn])
OR
(([DateDes] Is Null) and (Date()-[DateEntered]) >=
[Forms]![frmMainReport]![JRDesTurn])
)
AND
(
(([DateProd]-[DateDes]) >=
[Forms]![frmMainReport]![JRProdTurn])
OR
(([DateProd] Is Null) and (Date()-[DateDes]) >=
[Forms]![frmMainReport]![JRProdTurn])
)
AND
(
(([DateProd]-[DateEntered]) >=
[Forms]![frmMainReport]![JRTotalTurn])
OR
(([DateProd] Is Null) and (Date()-[DateRec]) >=
[Forms]![frmMainReport]![JRTotalTurn])
)
Now, the query can't be opened in SQL view (text too long to be edited), but
I DID notice that before I added a couple additional criteria, Access did
replace the original SQL that I typed in myself with a HUGE increase in text
after the query was run using the form (ie. I typed in the SQL string seen
above, saved and closed the query, opened the form whose recordsource is
this query, changed a fiew criteria and refreshed, and then came back to the
query and opened it in SQL view, and saw that there was at least 5 times the
amount of text and parenthetical phrases as what I had originally typed). I
don't know if Access automatically changing the logic to longer strings is
part of the problem or not.
I can make this DB available for DL if someone wants to see this behaviour
duplicated.
Can anyone tell me a way to accomplish the SQL string above without a "too
complex" error?