Hi!
I have a form, which has 3 fields. One is the date, the other is the meter value (TarA), and the last is the consumption (CTarA) which is the difference between the today's meter value and yesterday's. I also want to have the option to correct previous readings if necessary, and so I have the following code:
Private Sub TarA_AfterUpdate()
On Error GoTo Err_TarA_AfterUpdate
Dim TarAValue As Integer, PrevTarAValue As Integer, NextTarAValue As Integer
TarAValue = Me.TarA
Recordset.MovePrevious
PrevTarAValue = Me.TarA
Recordset.MoveNext
Me.CTarA = TarAValue - PrevTarAValue
Me.Form.Refresh
Recordset.MoveNext
NextTarAValue = Me.TarA
Me.CTarA = NextTarAValue - TarAValue
Me.Form.Refresh
Exit_TarA_AfterUpdate:
Exit Sub
Err_TarA_AfterUpdate:
MsgBox Err.Description
Resume Exit_TarA_AfterUpdate
End Sub
This works fine for correcting existing records but doesn't work for new records. I'm a beginner at this, so it will probably be something obvious...
Thanks for any help.
Kathrin
I have a form, which has 3 fields. One is the date, the other is the meter value (TarA), and the last is the consumption (CTarA) which is the difference between the today's meter value and yesterday's. I also want to have the option to correct previous readings if necessary, and so I have the following code:
Private Sub TarA_AfterUpdate()
On Error GoTo Err_TarA_AfterUpdate
Dim TarAValue As Integer, PrevTarAValue As Integer, NextTarAValue As Integer
TarAValue = Me.TarA
Recordset.MovePrevious
PrevTarAValue = Me.TarA
Recordset.MoveNext
Me.CTarA = TarAValue - PrevTarAValue
Me.Form.Refresh
Recordset.MoveNext
NextTarAValue = Me.TarA
Me.CTarA = NextTarAValue - TarAValue
Me.Form.Refresh
Exit_TarA_AfterUpdate:
Exit Sub
Err_TarA_AfterUpdate:
MsgBox Err.Description
Resume Exit_TarA_AfterUpdate
End Sub
This works fine for correcting existing records but doesn't work for new records. I'm a beginner at this, so it will probably be something obvious...
Thanks for any help.
Kathrin