K
Keith
I have a report in Access that is based on the following query:
SELECT [OPEN JOBS].CUSTOMER, [PART MASTER].[REF #], [OPEN JOBS].PART_NO,
[OPEN JOBS].JOB_NO, [OPEN JOB RELEASES].QTY, [OPEN JOB RELEASES].[DUE DATE],
JOB_INVENTORY([open jobs].[JOB_NO],[REF #],[INVENTORY COUNT],[QTY]) AS
release_inv, [PART MASTER].[INVENTORY COUNT], [PART MASTER].[PART
DESCRIPTION], [OPEN JOBS].[BLANKET ORDER], [OPEN JOBS].[UNIT PRICE], [UNIT
PRICE]*[QTY] AS ShipmentPrice, [OPEN JOBS].On_Hold, IIf([open
jobs].[CUSTOMER]="Cessna Aircraft Company",[DUE DATE]-7,"") AS CessnaShipDate
FROM ([OPEN JOB RELEASES] INNER JOIN ([PART MASTER] INNER JOIN [OPEN JOBS]
ON ([PART MASTER].CUSTOMER = [OPEN JOBS].CUSTOMER) AND ([PART MASTER].PART_NO
= [OPEN JOBS].PART_NO)) ON [OPEN JOB RELEASES].JOB_NO = [OPEN JOBS].JOB_NO)
INNER JOIN qryOpenJobReleasesSumNotFilled ON [OPEN JOBS].JOB_NO =
qryOpenJobReleasesSumNotFilled.JOB_NO
WHERE ((([OPEN JOB RELEASES].[DUE DATE])<=[Enter Date]) AND (([OPEN
JOBS].[BLANKET ORDER])=No) AND (([OPEN JOBS].[UNIT PRICE])<>0.001) AND
(([OPEN JOBS].On_Hold)=No) AND (([OPEN JOB RELEASES].FILLED)=No) AND (([OPEN
JOBS].[CLOSE DATE]) Is Null))
ORDER BY [PART MASTER].[REF #], [OPEN JOB RELEASES].[DUE DATE];
The query field release_inv require the data to be sorted as the ORDER BY
statement specifies (first by [PART MASTER].[REF #], then by [OPEN JOB
RELEASES].[DUE DATE]). That is because the JOB_INVENTORY function I created
stores values in a static variable based on the values passed to it in the
aforementioned ORDER BY statement. (see below)
Function JOB_INVENTORY(JOB As String, REF As Long, QTY As Long, CAP As Long)
As Long
Static REFVARIABLE As Long
Static QTYVARIABLE As Long
If IsNull(JOB) Or JOB = "" Then
QTYVARIABLE = 0
JOB_INVENTORY = 0
Else
If REF <> REFVARIABLE Then
REFVARIABLE = REF
If QTY >= CAP Then
JOB_INVENTORY = CAP
QTYVARIABLE = QTY - CAP
Else
JOB_INVENTORY = QTY
QTYVARIABLE = 0
End If
Else
If QTYVARIABLE >= CAP Then
JOB_INVENTORY = CAP
QTYVARIABLE = QTYVARIABLE - CAP
Else
JOB_INVENTORY = QTYVARIABLE
QTYVARIABLE = 0
End If
End If
End If
End Function
The problem is that I need to print out the results of the query in a report
that is sorted by [OPEN JOB RELEASES].[DUE DATE] only. I can create this
sorting in datasheet view of the query with noproblem, but, in the report,
the sorting causes the value of release_inv to come out differently.
It appears that the report recalculates the entire query when it applies
it's own sorting. Is there a way to control this behavior? The only thing I
can think of is to change the query to a MakeTable and base the report on the
resultant table. This will work, but it seems like a clunky solution.
Does anyone have any better ideas?
Thanks,
Keith
SELECT [OPEN JOBS].CUSTOMER, [PART MASTER].[REF #], [OPEN JOBS].PART_NO,
[OPEN JOBS].JOB_NO, [OPEN JOB RELEASES].QTY, [OPEN JOB RELEASES].[DUE DATE],
JOB_INVENTORY([open jobs].[JOB_NO],[REF #],[INVENTORY COUNT],[QTY]) AS
release_inv, [PART MASTER].[INVENTORY COUNT], [PART MASTER].[PART
DESCRIPTION], [OPEN JOBS].[BLANKET ORDER], [OPEN JOBS].[UNIT PRICE], [UNIT
PRICE]*[QTY] AS ShipmentPrice, [OPEN JOBS].On_Hold, IIf([open
jobs].[CUSTOMER]="Cessna Aircraft Company",[DUE DATE]-7,"") AS CessnaShipDate
FROM ([OPEN JOB RELEASES] INNER JOIN ([PART MASTER] INNER JOIN [OPEN JOBS]
ON ([PART MASTER].CUSTOMER = [OPEN JOBS].CUSTOMER) AND ([PART MASTER].PART_NO
= [OPEN JOBS].PART_NO)) ON [OPEN JOB RELEASES].JOB_NO = [OPEN JOBS].JOB_NO)
INNER JOIN qryOpenJobReleasesSumNotFilled ON [OPEN JOBS].JOB_NO =
qryOpenJobReleasesSumNotFilled.JOB_NO
WHERE ((([OPEN JOB RELEASES].[DUE DATE])<=[Enter Date]) AND (([OPEN
JOBS].[BLANKET ORDER])=No) AND (([OPEN JOBS].[UNIT PRICE])<>0.001) AND
(([OPEN JOBS].On_Hold)=No) AND (([OPEN JOB RELEASES].FILLED)=No) AND (([OPEN
JOBS].[CLOSE DATE]) Is Null))
ORDER BY [PART MASTER].[REF #], [OPEN JOB RELEASES].[DUE DATE];
The query field release_inv require the data to be sorted as the ORDER BY
statement specifies (first by [PART MASTER].[REF #], then by [OPEN JOB
RELEASES].[DUE DATE]). That is because the JOB_INVENTORY function I created
stores values in a static variable based on the values passed to it in the
aforementioned ORDER BY statement. (see below)
Function JOB_INVENTORY(JOB As String, REF As Long, QTY As Long, CAP As Long)
As Long
Static REFVARIABLE As Long
Static QTYVARIABLE As Long
If IsNull(JOB) Or JOB = "" Then
QTYVARIABLE = 0
JOB_INVENTORY = 0
Else
If REF <> REFVARIABLE Then
REFVARIABLE = REF
If QTY >= CAP Then
JOB_INVENTORY = CAP
QTYVARIABLE = QTY - CAP
Else
JOB_INVENTORY = QTY
QTYVARIABLE = 0
End If
Else
If QTYVARIABLE >= CAP Then
JOB_INVENTORY = CAP
QTYVARIABLE = QTYVARIABLE - CAP
Else
JOB_INVENTORY = QTYVARIABLE
QTYVARIABLE = 0
End If
End If
End If
End Function
The problem is that I need to print out the results of the query in a report
that is sorted by [OPEN JOB RELEASES].[DUE DATE] only. I can create this
sorting in datasheet view of the query with noproblem, but, in the report,
the sorting causes the value of release_inv to come out differently.
It appears that the report recalculates the entire query when it applies
it's own sorting. Is there a way to control this behavior? The only thing I
can think of is to change the query to a MakeTable and base the report on the
resultant table. This will work, but it seems like a clunky solution.
Does anyone have any better ideas?
Thanks,
Keith