Okay, Phil. Now we have something specific to work with.
Let's try with just this one field, and no grouping, so we can be certain
where the problem lies:
SELECT ([invoice_d]![price] *
(1 + CDbl(Nz([invoice_d]![discount],0))/100) *
[invoice_d]![ship_qty]) AS Extended_Gross
FROM ((((invoice_d LEFT JOIN invoice_h ON invoice_d.invoice_id =
invoice_h.invoice_id) LEFT JOIN item ON invoice_d.item_id = item.item_id)
LEFT JOIN item_types ON item.item_type = item_types.type_id) LEFT JOIN
customer ON invoice_h.customer_id = customer.customer_id) LEFT JOIN
customer_type ON customer.customer_type_id = customer_type.customer_type_id
I have guessed that the discount is the one that is causing the issue, so
have forced it to double at the lowest level, and then handled it as
fractional values.
If that still fails, what are invoice_d and invoice_h? Are they queries?
Tables? Access tables? Linked dBase tables? ...?
If they are queries, you may need to perform the typecasting in the lower
queries. If tables, when you open in design view, what is the data type of
the price, discount, and ship_qty fields?
Another option is to try to break the field down further, i.e.:
SELECT [invoice_d]![price],
(1 + CDbl(Nz([invoice_d]![discount],0))/100) AS Rate,
[invoice_d]![ship_qty]
FROM ((((invoice_d LEFT JOIN invoice_h ON invoice_d.invoice_id =
invoice_h.invoice_id) LEFT JOIN item ON invoice_d.item_id = item.item_id)
LEFT JOIN item_types ON item.item_type = item_types.type_id) LEFT JOIN
customer ON invoice_h.customer_id = customer.customer_id) LEFT JOIN
customer_type ON customer.customer_type_id = customer_type.customer_type_id
If that works, you might be able to get a clue on how JET is understanding
it by opening the Immediate Window (Ctrl+G), and entering:
? TypeName(DLookup("Rate", "Query1"))
etc.
Also, if any of these separate fields displays left-aligned, Access is
understanding it as text (not numeric.)
Another option is to work with just invoice_d since all 3 fields in the
problem expression are from that "table". This might help identify the issue
if the problem were part of the join rather than the expression:
SELECT ([invoice_d]![price] *
(1 + CDbl(Nz([invoice_d]![discount],0))/100) *
[invoice_d]![ship_qty]) AS Extended_Gross
FROM invoice_d;
HTH
--
Allen Browne - Microsoft MVP. Perth, Western Australia.
Reply to group, rather than allenbrowne at mvps dot org.
Phil said:
This fails even as a SELECT query.
SELECT customer_type.name, invoice_h.prebook_id, item_types.name,
Sum([invoice_d]![price]*((100+[invoice_d]![discount])/100)*[invoice_d]![ship_qty])
AS Extended_Gross,
Sum([invoice_d]![price]*[invoice_d]![ship_qty]) AS
Extended_Net
FROM ((((invoice_d LEFT JOIN invoice_h ON invoice_d.invoice_id =
invoice_h.invoice_id) LEFT JOIN item ON invoice_d.item_id = item.item_id)
LEFT JOIN item_types ON item.item_type = item_types.type_id) LEFT JOIN
customer ON invoice_h.customer_id = customer.customer_id) LEFT JOIN
customer_type ON customer.customer_type_id =
customer_type.customer_type_id
GROUP BY customer_type.name, invoice_h.prebook_id, item_types.name;
The isolated line is the problem child. Remove it, query fine.
I changed it to
CDbl(NZ(Sum(CDbl(NZ([invoice_d]![price],0))*((100+CDbl(NZ([invoice_d]![discount],0))/100))*CDbl(NZ([invoice_d]![ship_qty],0)))))
isolating every single piece and forcing it to a Double, as well as
forcing the whole thing as a double, same answer.