Calculated field returning #Error (1 Viewer)

miaki16

New member
Local time
Today, 06:29
Joined
May 6, 2008
Messages
9
I am making an application to track methanol usage in an oil and gas field throughout the winter months in Canada.

I have a query set up to do several simple but time consuming calculations. There query determines the volume in the tank at the start of the fall based on a measurement, the volume in the tank at the end of spring based on another measurement, and I would like it to determine the methanol usage over the time period. Since methanol may be added during the winter if the storage tanks get low I sometimes need to add a fixed number(s) to the difference of the two fall and spring volumes.

The problem I am having is that not all the tanks get refilled during the winter months. I am using a DSUM function to calculate the total amount of methanol added between the spring and fall dates. If the tanks don’t get refilled, the DSUM function appears to return a null or an empty entry, then when I add the three fields FallVolume, Spring Volume, and AddedMethanol, I get a #Error in the calculated field MethanolUsage. I have tried using IIf(Iserror([AddedMethanol], as well as both IIf(IsNull([AddedMethanol and IsEmpty(). These don’t seem to work help either. I have also tried using the Nz function when calculating [Addedmethanol] and forcing it to return “0.00” if it results in a null value. I have searched the forum and the web and have come up empty so far. At this point I am stumped why it is not working. Any help would be much appreciated.

Thanks, Mike

MethanolUsage for the first record should be 1085.05

FallVolume: FormatNumber(DLookUp("[Volume]","[tblTankGaugeCharts]","[DipDepth]=" & [FallDipReading] & "And [TankID]=" & [MethanolTankID]),2,0)

SpringVolume: FormatNumber(DLookUp("[Volume]","[tblTankGaugeCharts]","[DipDepth]=" & [SpringDipReading] & "And [TankID]=" & [MethanolTankID]),2,0)
 

Attachments

  • qryAnalysis.JPG
    qryAnalysis.JPG
    27.7 KB · Views: 627

DCrake

Remembered
Local time
Today, 13:29
Joined
Jun 8, 2005
Messages
8,632
This is because you have a null value in one of your calculated fields. You will need to wrap Nz() around each field that could potentially be null.

Read further after post but this is still the issue. Cannot add something to nothing.

PS I used to live in Calgary many moons ago in a place called Fairview. Ever heard of it?
 

miaki16

New member
Local time
Today, 06:29
Joined
May 6, 2008
Messages
9
Thanks David. I have wrapped all the calculated fields that may return nulls in the Nz() function and I am still getting the same #Error. Here are my new calculated fields:

FallVolume: Nz(FormatNumber(DLookUp("[Volume]","[tblTankGaugeCharts]","[DipDepth]=" & [FallDipReading] & "And [TankID]=" & [MethanolTankID]),2,0),"0.00")

SpringVolume: Nz(FormatNumber(DLookUp("[Volume]","[tblTankGaugeCharts]","[DipDepth]=" & [SpringDipReading] & "And [TankID]=" & [MethanolTankID]),2,0),"0.00")

Nz(FormatNumber(DSum("[RefillVolume]","[tblRefills]","[tblRefills]![RefillDate] Between #" & [FallDipDate] & "# And # " & [SpringDipDate] & "# And [tblRefills]![UWI] ='" & [UWI] & "'"),2,0),"0.00")

MethanolUsage: Nz([FallVolume],"0.00")-Nz([SpringVolume],"0.00")+Nz([AddedMethanol],"0.00")

Mike
 

miaki16

New member
Local time
Today, 06:29
Joined
May 6, 2008
Messages
9
David,

I figured it out. I played with the placement of the Nz() function and it now calculates as expected. Thanks for your help and pointing me in the right direction. Greatly appreciated!

As for Fairview, I have heard of it. In fact one of my operators that I am constructing the database for requests me to visit a small store in the Fairview to buy some hot sauce from and deliver when I visit the field!

Thanks again for your help.

Mike
 

Users who are viewing this thread

Top Bottom