G
Glint
Hi All,
I built a select query based on one table (AssetsGeneral) that looks like a
behemoth thus:
SELECT AssetsGeneral.ItemID, AssetsGeneral.ItemName,
AssetsGeneral.ModelNumber, AssetsGeneral.SerialNumber,
AssetsGeneral.AssetCategory, AssetsGeneral.DateAcquired,
AssetsGeneral.PurchasePrice, AssetsGeneral.EstimatedValue,
AssetsGeneral.SalvageValue,
IIf(IsNull(DLookUp("[DepreciationRate]","AssetsGeneralCategory","[CategoryID]="
&
[AssetCategory])),Null,CInt(365*(100/DLookUp("[DepreciationRate]","AssetsGeneralCategory","[CategoryID]="
& [AssetCategory]))*([EstimatedValue]-[SalvageValue])/[EstimatedValue])) AS
DepreciableLife,
IIf([EstimatedValue]-NZ(DateDiff("d",[DateAcquired],Date()),0)*[EstimatedValue]*NZ(DLookUp("[DepreciationRate]/365","AssetsGeneralCategory","[CategoryID]="
& [AssetCategory]),0)>=DLookUp("[SalvageValue]","AssetsGeneral","[ItemID]=" &
[ItemID]),NZ(DateDiff("d",[DateAcquired],Date()),0)*[EstimatedValue]*NZ(DLookUp("[DepreciationRate]/365","AssetsGeneralCategory","[CategoryID]="
&
[AssetCategory]),0),[EstimatedValue]-DLookUp("[SalvageValue]","AssetsGeneral","[ItemID]="
& [ItemID])) AS DTD, [EstimatedValue]-[DTD] AS NBV,
IIf(IsNull(Forms!TB!SDate),Null,IIf(IsNull(DLookUp("[DepreciationRate]","AssetsGeneralCategory","[CategoryID]="
&
[AssetCategory])),0,IIf([DateAcquired]>Forms!TB!SDate,0,IIf(DateDiff("d",[DateAcquired],Forms!TB!SDate)>=[DepreciableLife],[EstimatedValue]-[SalvageValue],NZ(DateDiff("d",[DateAcquired],Forms!TB!SDate),0)*[EstimatedValue]*NZ(DLookUp("[DepreciationRate]/36500","AssetsGeneralCategory","[CategoryID]="
& [AssetCategory]),0))))) AS DTDTBS,
IIf(IsNull(Forms!TB!EDate),Null,IIf(IsNull(DLookUp("[DepreciationRate]","AssetsGeneralCategory","[CategoryID]="
&
[AssetCategory])),0,IIf([DateAcquired]>Forms!TB!EDate,0,IIf(DateDiff("d",[DateAcquired],Forms!TB!EDate)>=[DepreciableLife],[EstimatedValue]-[SalvageValue],NZ(DateDiff("d",[DateAcquired],Forms!TB!EDate),0)*[EstimatedValue]*NZ(DLookUp("[DepreciationRate]/36500","AssetsGeneralCategory","[CategoryID]="
& [AssetCategory]),0))))) AS DTDTBE, [DTDTBE]-[DTDTBS] AS DTDTBNet,
[EstimatedValue]-[DTDTBE] AS NBVTBE
FROM AssetsGeneral
WHERE (((AssetsGeneral.Disposed) Is Null));
This query works fine and returns records on the click of the mouse.
Then I based two fields of another query on this query thus:
Value:
IIf([BKID]=1,Format(NZ(DSum("[DTDTBNet]","vCurrentAssetsDepBK"),0),"Standard"),Format(-NZ(DSum("[DTDTBNet]","vCurrentAssetsDepBK"),0),"Standard"))
And Cum:
IIf([BKID]=1,Format(NZ(DSum("[DTDTBE]","vCurrentAssetsDepBK"),0),"Standard"),Format(-NZ(DSum("[DTDTBE]","vCurrentAssetsDepBK"),0),"Standard"))
This time, it ages to return results; you could almost finish a coffee, if
it takes you up to a minute to drink one. I cannot figure what is wrong. When
I remove the fields, the query if fast enough; but with either of them, it is
slow (more with the two together). Can you help me? Is there another way I
could accomplish the task?
I built a select query based on one table (AssetsGeneral) that looks like a
behemoth thus:
SELECT AssetsGeneral.ItemID, AssetsGeneral.ItemName,
AssetsGeneral.ModelNumber, AssetsGeneral.SerialNumber,
AssetsGeneral.AssetCategory, AssetsGeneral.DateAcquired,
AssetsGeneral.PurchasePrice, AssetsGeneral.EstimatedValue,
AssetsGeneral.SalvageValue,
IIf(IsNull(DLookUp("[DepreciationRate]","AssetsGeneralCategory","[CategoryID]="
&
[AssetCategory])),Null,CInt(365*(100/DLookUp("[DepreciationRate]","AssetsGeneralCategory","[CategoryID]="
& [AssetCategory]))*([EstimatedValue]-[SalvageValue])/[EstimatedValue])) AS
DepreciableLife,
IIf([EstimatedValue]-NZ(DateDiff("d",[DateAcquired],Date()),0)*[EstimatedValue]*NZ(DLookUp("[DepreciationRate]/365","AssetsGeneralCategory","[CategoryID]="
& [AssetCategory]),0)>=DLookUp("[SalvageValue]","AssetsGeneral","[ItemID]=" &
[ItemID]),NZ(DateDiff("d",[DateAcquired],Date()),0)*[EstimatedValue]*NZ(DLookUp("[DepreciationRate]/365","AssetsGeneralCategory","[CategoryID]="
&
[AssetCategory]),0),[EstimatedValue]-DLookUp("[SalvageValue]","AssetsGeneral","[ItemID]="
& [ItemID])) AS DTD, [EstimatedValue]-[DTD] AS NBV,
IIf(IsNull(Forms!TB!SDate),Null,IIf(IsNull(DLookUp("[DepreciationRate]","AssetsGeneralCategory","[CategoryID]="
&
[AssetCategory])),0,IIf([DateAcquired]>Forms!TB!SDate,0,IIf(DateDiff("d",[DateAcquired],Forms!TB!SDate)>=[DepreciableLife],[EstimatedValue]-[SalvageValue],NZ(DateDiff("d",[DateAcquired],Forms!TB!SDate),0)*[EstimatedValue]*NZ(DLookUp("[DepreciationRate]/36500","AssetsGeneralCategory","[CategoryID]="
& [AssetCategory]),0))))) AS DTDTBS,
IIf(IsNull(Forms!TB!EDate),Null,IIf(IsNull(DLookUp("[DepreciationRate]","AssetsGeneralCategory","[CategoryID]="
&
[AssetCategory])),0,IIf([DateAcquired]>Forms!TB!EDate,0,IIf(DateDiff("d",[DateAcquired],Forms!TB!EDate)>=[DepreciableLife],[EstimatedValue]-[SalvageValue],NZ(DateDiff("d",[DateAcquired],Forms!TB!EDate),0)*[EstimatedValue]*NZ(DLookUp("[DepreciationRate]/36500","AssetsGeneralCategory","[CategoryID]="
& [AssetCategory]),0))))) AS DTDTBE, [DTDTBE]-[DTDTBS] AS DTDTBNet,
[EstimatedValue]-[DTDTBE] AS NBVTBE
FROM AssetsGeneral
WHERE (((AssetsGeneral.Disposed) Is Null));
This query works fine and returns records on the click of the mouse.
Then I based two fields of another query on this query thus:
Value:
IIf([BKID]=1,Format(NZ(DSum("[DTDTBNet]","vCurrentAssetsDepBK"),0),"Standard"),Format(-NZ(DSum("[DTDTBNet]","vCurrentAssetsDepBK"),0),"Standard"))
And Cum:
IIf([BKID]=1,Format(NZ(DSum("[DTDTBE]","vCurrentAssetsDepBK"),0),"Standard"),Format(-NZ(DSum("[DTDTBE]","vCurrentAssetsDepBK"),0),"Standard"))
This time, it ages to return results; you could almost finish a coffee, if
it takes you up to a minute to drink one. I cannot figure what is wrong. When
I remove the fields, the query if fast enough; but with either of them, it is
slow (more with the two together). Can you help me? Is there another way I
could accomplish the task?