This is kind of long, but here's the code. The score field for each
question in each qroup is set to run the corresponding code on exit.
(FYI...DepartmentKnowledge is a single score and does not need an average -
it just gets transferred to the summary page using Summary_Transfer)
Sub Summary_Transfer()
With ActiveDocument
If .FormFields("DepartmentKnowledge").Result = "1" Then
.FormFields("DepartmentSummary").Result = "1"
ElseIf .FormFields("DepartmentKnowledge").Result = "2" Then
.FormFields("DepartmentSummary").Result = "2"
ElseIf .FormFields("DepartmentKnowledge").Result = "3" Then
.FormFields("DepartmentSummary").Result = "3"
ElseIf .FormFields("DepartmentKnowledge").Result = "4" Then
.FormFields("DepartmentSummary").Result = "4"
ElseIf .FormFields("DepartmentKnowledge").Result = "5" Then
.FormFields("DepartmentSummary").Result = "5"
Else: .FormFields("DepartmentSummary").Result = "0"
End If
End With
End Sub
Sub Perform_CoreKnowledgeAverage()
Dim i As Long, j As Long
Dim Total As Double
Dim ffname As String
Total = 0
i = 0
With ActiveDocument
For j = 1 To 7
ffname = "CoreKnowledge0" & j
If Val(.FormFields(ffname).Result) <> 0 Then
Total = Total + .FormFields(ffname).Result
i = i + 1
End If
Next j
If i > 0 Then
.FormFields("TotalCoreKnowledge").Result = Total / i
.FormFields("CoreKnowledgeSummary").Result = Total / i
Else
.FormFields("TotalCoreKnowledge").Result = 0
.FormFields("CoreKnowledgeSummary").Result = 0
End If
End With
End Sub
Sub Perform_Compentancy_Average()
Dim k As Long, l As Long
Dim Total As Double
Dim ffname As String
Total = 0
k = 0
With ActiveDocument
For l = 1 To 12
ffname = "Comp0" & l
If Val(.FormFields(ffname).Result) <> 0 Then
Total = Total + .FormFields(ffname).Result
k = k + 1
End If
Next l
If k > 0 Then
.FormFields("TotalComp").Result = Total / k
.FormFields("CompSummary").Result = Total / k
Else
.FormFields("TotalComp").Result = 0
.FormFields("CompSummary").Result = 0
End If
End With
End Sub
Sub Perform_Values_Average()
Dim o As Long, p As Long
Dim Total As Double
Dim ffname As String
Total = 0
o = 0
With ActiveDocument
For p = 1 To 8
ffname = "Values0" & p
If Val(.FormFields(ffname).Result) <> 0 Then
Total = Total + .FormFields(ffname).Result
o = o + 1
End If
Next p
If o > 0 Then
.FormFields("TotalValues").Result = Total / o
.FormFields("ValuesSummary").Result = Total / o
Else
.FormFields("TotalValues").Result = 0
.FormFields("ValuesSummary").Result = 0
End If
End With
End Sub
Once these calculations are done, I have a form field (GrandAverage) that is
set as a calculation type with this calculation:
=(DepartmentSummary + CoreKnowledgeSummary + CompSummary + ValuesSummary) / 4
Boy, I sure hope all this makes sense to you! It is kind of hard to explain
without showing you the document. Once again, I really appreciate your help!