John W. Vinson said:
Please post the SQL of the query.
Here is the SQL of the query that works - with calculations done in the
expression:
SELECT tblProduct.ProductSKU, tblProduct.ProductName,
tblWarehouseLocation.WarehouseLocation,
IIf((Mid([tblProduct].[ProductNormalMonths],(CStr(Month(Now()))),1))="1",[tblProduct].[ProductNormalStockingLevel],IIf((Mid([tblProduct].[ProductLowMonths],(CStr(Month(Now()))),1))="1",[tblProduct].[ProductLowStockingLevel],[tblProduct].[ProductHighStockingLevel]))*[tblWarehouseLocation].[WarehouseLocationMultiplier]
AS [Minimum Level],
[tblWarehouseLocation].[WarehouseLocationQty]*[tblWarehouseLocation].[WarehouseLocationMultiplier] AS [Current Level]
FROM tblProduct INNER JOIN tblWarehouseLocation ON tblProduct.ProductSKU =
tblWarehouseLocation.WarehouseLocationSKU
GROUP BY tblProduct.ProductSKU, tblProduct.ProductName,
tblWarehouseLocation.WarehouseLocation,
IIf((Mid([tblProduct].[ProductNormalMonths],(CStr(Month(Now()))),1))="1",[tblProduct].[ProductNormalStockingLevel],IIf((Mid([tblProduct].[ProductLowMonths],(CStr(Month(Now()))),1))="1",[tblProduct].[ProductLowStockingLevel],[tblProduct].[ProductHighStockingLevel]))*[tblWarehouseLocation].[WarehouseLocationMultiplier],
[tblWarehouseLocation].[WarehouseLocationQty]*[tblWarehouseLocation].[WarehouseLocationMultiplier],
tblWarehouseLocation.WarehouseLocationQty,
IIf((Mid([tblProduct].[ProductNormalMonths],(CStr(Month(Now()))),1))="1",[tblProduct].[ProductNormalStockingLevel],IIf((Mid([tblProduct].[ProductLowMonths],(CStr(Month(Now()))),1))="1",[tblProduct].[ProductLowStockingLevel],[tblProduct].[ProductHighStockingLevel])), tblProduct.ProductVendor1ID
HAVING
(((([tblWarehouseLocation].[WarehouseLocationQty]*[tblWarehouseLocation].[WarehouseLocationMultiplier])-(IIf((Mid([tblProduct].[ProductNormalMonths],(CStr(Month(Now()))),1))="1",[tblProduct].[ProductNormalStockingLevel],IIf((Mid([tblProduct].[ProductLowMonths],(CStr(Month(Now()))),1))="1",[tblProduct].[ProductLowStockingLevel],[tblProduct].[ProductHighStockingLevel]))*[tblWarehouseLocation].[WarehouseLocationMultiplier]))<0))
ORDER BY tblProduct.ProductVendor1ID;
Below is an attempt to use function in Query - This query is not the same as
above - just trying to use the function in the query field:
SQL:
SELECT tblProduct.ProductSKU, tblProduct.ProductName
FROM tblProduct INNER JOIN tblWarehouseLocation ON tblProduct.ProductSKU =
tblWarehouseLocation.WarehouseLocationSKU;
Query Field:
My Function:
GetStockingLevel([ProductLowMonths],[ProductNormalMonths],[ProductHighMonths],[ProductLowStockingLevel],[ProductNormalStockingLevel],[ProductHighStockingLevel])
VBA Function:
Public Function GetStockingLevel(LowBitMap As String, NormalBitMap As
String, HighBitMap As String, LowLevel As String, NormalLevel As String,
HighLevel As String)
' This function returns the stocking level based on the bit map fields.
There are 6 fields all Strings
' Low Stocking Level Bit Map - example 110000000111 - would indicate Jan,
Feb, Oct, Nov, Dec
' Normal Stocking Level Bit Map
' High Stocking Level Bit Map
' Low Stocking Level - level to be used in Low Month
' Normal Stocking Level - level to be used in Normal Month
' High Stocking Level - level to be used in High Month
Dim BitIndex
Dim LowBit
Dim NormalBit
Dim HighBit
BitIndex = CStr(Month(Now()))
LowBit = Mid(LowBitMap, BitIndex, 1)
NormalBit = Mid(NormalBitMap, BitIndex, 1)
'HighBit = Mid(HighBitMap, BitIndex, 1)
GetStockingLevel = IIf(NormalBit = "1", NormalLevel, IIf(LowBit = "1",
LowLevel, HighLevel))
End Function
Thanks