Variable results in calculation

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I am using a form which has several calculated fields. I am trying to
display when the next maintenance is due on an engine after the day's entry
is made. It seemed to be working fine when I had data in the "tblflights"
table, but when I deleted the records there and tried again, the calculated
results were not correct.

thanks for any help you can offer.

Dim NextSPMaint As Double

NextSPMaint = DLast("[EngineHrs]", "tblEngineMaintenance", _
"[SerialNumber] = EngineTxt.Value And [Type] = 'Spark Plug'") + 40
txtNextSPMaint.Value = NextSPMaint

If DCount("Engine", "tblFlights", "[Engine] = [EngineTxt]") = 0 Then
TotalEngHrs.Value = TxtEnginetime.Value + DLookup("[EngineHours]", _
"[tblEngine]", "[SerialNumber] = [EngineTxt]")
Else
TotalEngHrs.Value = DSum("([Land] - [EngineStart]) * 24",
"tblFlights", _
[Engine] = EngineTxt.Value) + TxtEnginetime.Value + _
DLookup("[EngineHours]", "[tblEngine]", "[SerialNumber] =
[EngineTxt]")
End If

txtSPMaint.Value = NextSPMaint - TotalEngHrs.Value
If NextSPMaint - TotalEngHrs.Value < 2 Then
txtSPMaint.ForeColor = vbRed
Else: txtSPMaint.Value = vbBlack
End If
-
Teach me to fish! Thanks for the help.
Pax, M
 
Hi Fisherman

Please let us know what is wrong with the calculated results?

Also, if you have deleted all the data in the tblFlights table then your If
statement is irrelevant as the DCount function will only ever return a zero
as there is nothing to count - is this what you want, or are you intending
populating the table later with data?

Cheers.

BW
 
Try DMax() instead of DLast().

DMax() gives the highest value (hence the most recent date), whereas DLast()
just finds the last thing however it happens to be sorted.
 
Back
Top