Private Sub Calories_BeforeUpdate(Cancel As Integer)
On Error GoTo Err_Calories_BeforeUpdate
BodyDataBigChange "CALORIES", "Calories", Me.Date, Me.Calories
Exit_Calories_BeforeUpdate:Exit Sub
Err_Calories_BeforeUpdate: MsgBox "Form_ScalesF, Calories_BeforeUpdate, Error number: " & Err.Number & "" & vbNewLine & "" & Err.Description & ""
Resume Exit_Calories_BeforeUpdate
End Sub
-------------------------------------------------------------------------
Public Sub BodyDataBigChange(ByVal strNameField As String, ByVal strField As String, ByVal dtDate As Date, ByVal varNewValue As Variant)
On Error GoTo Err_BodyDataBigChange Dim varPrevValue As Variant
Dim dtPrevDate As Date
Dim strCriteria As String
Dim strDtCriteria As String
Dim strValCriteria As String
If varNewValue = -1 Or IsNull(
varNewValue)
Then GoTo Exit_BodyDataBigChange
End If strDtCriteria = "Date < #" & Format(
dtDate, "mm\/dd\/yyyy") & "#"
strValCriteria = "((not isnull(" &
strField & ")) and (not isempty(" &
strField & ")))"
strCriteria = "" &
strDtCriteria & " and " &
strValCriteria & ""
'find the date of the latest entry prior to the current entry
If IsNull(DMax("Date", "ScalesT",
strCriteria))
ThenGoTo Exit_BodyDataBigChange
ElsedtPrevDate = DMax("Date", "ScalesT", strCriteria)
End If
'set the date criteria for getting the previous entry
strDtCriteria = "Date = #" & Format(
dtPrevDate, "mm\/dd\/yyyy") & "#"
strCriteria = "" &
strDtCriteria & " and " &
strValCriteria & ""
varPrevValue = DLookup(
strField, "ScalesT",
strCriteria)
'check if the new entry is more than 20% different to the last one
'if the difference between the NewValue and PrevValue is > 20% then warn the user
If Abs((
varPrevValue -
varNewValue) /
varPrevValue) > 0.2
Then MsgBox "The value you have entered for " & strNameField & " is a change more than 20% of the previous value." & vbNewLine & "" & _
"The previous entry was for: " & FormatDateTime(dtPrevDate, vbLongDate) & "" & vbNewLine & "" & vbNewLine & "" & _
"You may have entered an incorrect value.", vbInformation, "DATA: Check entry"
End If Exit_BodyDataBigChange: Exit Sub
Err_BodyDataBigChange: MsgBox "FitLogLib, BodyDataBigChange, Error number: " & Err.Number & ", " & vbNewLine & "" & Err.Description & ""
Resume Exit_BodyDataBigChange
End Sub
-----------------------------------------------------------------------
The aberrant action of the graph opening only happens if the BodyDataBigChange sub puts up the msgbox.