Dear all
Apologies in advance. This may seem so simple. But I am self taught and can just not figure out where I have gone wrong. Looking for assistance - for this (and something else that will post seperately).
So - I have 7 controls on a form:
- SR06_Datapoints
- SR10_Datapoints
- SR15_Datapoints
- GAP_Datapoints
- LEGACY_Datapoints
- NonReg_Datapoints
- Total_Included_Datapoints
Number 6 should be the total of number 4 and 5 and Number 7 should be the total of items 1 to 5.
I basically want anytime I enter a value in number 1, 2, 3, 4 or 5, for the entries in number 5 (if appropriate) to update and the entry in number 7 to update, as I move to the next control.
I have tried for 7 to create a function as follows:
Option Explicit
Public Function CalculateIncludedDatapoints(SR06 As Variant, SR10 As Variant, SR15 As Variant, GAP As Variant, LEGACY As Variant) As Variant
Dim IncludedDatapoints As Variant
IncludedDatapoints = SR06 + SR10 + SR15 + GAP + LEGACY
CalculateIncludedDatapoints = IncludedDatapoints
End Function
Then in the before update event in the control I have put:
Private Sub Total_Included_Datapoints_BeforeUpdate(Cancel As Integer)
Me.[Total_Included Datapoints] = CalculateIncludedDatapoints(Me.[SR06_Datapoints], Me.[SR10_Datapoints], Me.[SR15_Datapoints], Me.[GAP_Datapoints], Me.[LEGACY_Datapoints])
End Sub
This does not seem to work when I add data in each field. I tried adding the same codse in the above sub into the before update events in controls for items 1 to 5, but didn't work.
I am sure there may bea more elegant bit of code than the "CalculateIncludedDatapoints", either that or I am just calling it wrong. Any assistancew ill be very much appreciated.
Jonathan