How to update parent doc from responses

I need to update TotalValue in the parent doc when there is Number entered in each response document. But i am not able to get the totals of Number field and replace the TotalValue in parent doc.

Here is what i am trying from response Postsave…

Dim session As New NotesSession

Dim db As NotesDatabase

Set db = session.CurrentDatabase

Dim parent As NotesDocument

Set parent = db.GetDocumentByUNID ( Source.Document.ParentDocumentUNID)

Dim collection As NotesDocumentCollection

Set collection = parent.Responses

Dim currentResponse As NotesDocument

Set currentResponse = collection.GetFirstDocument

While Not ( currentResponse Is Nothing )

Dim TotalValue As Variant

Dim sum As Double

sum = 0

TotalValue = currentResponse.GetItemValue("Number")		

	

For i = 0 To collection.Count

	sum = sum + TotalValue(0)

Next



Set currentResponse = collection.GetNextDocument(currentResponse)		

Wend

Call parent.ReplaceItemValue(“TotalValue”, sum)

Subject: How to update parent doc from responses

Dim TotalValue As VariantDim sum As Double

sum = 0

Move these lines outside the loop otherwise these vars get initialized over and over again and loose their old values