Variable results in calculation

M

m stroup

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
 
B

BeWyched

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
 
A

Allen Browne

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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads

Multiple Criteria 2
Edit record via calculation 1

Top