Hi, I have a form with a sub form.
The subform allows (up to) 4 entries with only one variable (Score).
I want to total up the scores, divide it by the total number of scores recorded and then return the result to the parent form into a bound variable (Score).
All of this works great.... with the one acception that the result is from BEFORE the update not After the update (e.g. if the scores are 9,10,10,10 and then I change the 9 to a 10, you'd expect to see an average of 10, but instead the average is 9.75 (e.g. the average is being calculated from the values PRE-update, not after the update).
Here is my code:
If I run through the code using F8 it works perfectly, so I belive the issue is that the fields are being populated BEFORE the first line of functional code (this bit: Me.SubFormSum.Requery) is actually taking effect for some reason.
Much appreciated for any suggestions.
Cheers
The subform allows (up to) 4 entries with only one variable (Score).
I want to total up the scores, divide it by the total number of scores recorded and then return the result to the parent form into a bound variable (Score).
All of this works great.... with the one acception that the result is from BEFORE the update not After the update (e.g. if the scores are 9,10,10,10 and then I change the 9 to a 10, you'd expect to see an average of 10, but instead the average is 9.75 (e.g. the average is being calculated from the values PRE-update, not after the update).
Here is my code:
Code:
Dim SubCount As Integer, SubSum As Integer, SubAverage As Double, SubScore As Double, Result As String
[COLOR=#73D216]'My attempt to get the variable that hold sum of scores to update before the below code takes effect (this doesn't appear to work).[/color]
Me.SubFormSum.Requery
DoEvents
[COLOR=#73D216]'counts the number of scores entered[/color]
SubCount = Form.Recordset.RecordCount
SubSum = Me.SubFormSum.Value
[COLOR=#73D216]'below divides the 2 above variables[/color]
SubScore = SubSum / SubCount
[COLOR=#73D216]'enters the above result into the bound object on the parent form[/color]
[Forms]![SFLF_Benchmarking_Info].Score = SubScore
[COLOR=#73D216]'below changes another bound variable based on the above sum[/color]
Result = ""
If SubScore <= 5.5 Then
Result = "RE-TEST"
Else
End If
[Forms]![SFLF_Benchmarking_Info].Action = Result
If I run through the code using F8 it works perfectly, so I belive the issue is that the fields are being populated BEFORE the first line of functional code (this bit: Me.SubFormSum.Requery) is actually taking effect for some reason.
Much appreciated for any suggestions.
Cheers