Tip

Calculating Totals From Response Docs And Populate Field

THE PURPOSE OF THIS SCRIPT IS TO CALCULATE THE TOTAL OF THE A NUM BER/CURRENCY
FIELD FROM ALL THE RESPONSE DOCUMENTS AND POPULATE A FIELD IN THE PARENT
DOCUMENT WITH THAT TOTAL
Sub Queryclose(Source As Notesuidocument, Continue As Variant)

%REM
THE PURPOSE OF THIS SCRIPT IS TO CALCULATE THE TOTAL OF THE ACTUAL SAVINGS FROM
THE RES-
PONSE DOCUMENTS AND POPULATE THE ACTUAL SAVINGS FIELD IN THE PARENT DOCUMENT
%END REM

'DECLARING ALL THE VARABLES
Dim count As Integer
Dim workspace As New NotesUIWorkspace
Dim newamount As Variant
Dim currentdoc As NotesDocument
Dim dbase As NotesDatabase
Dim Session As New NotesSession
Dim responsedoc As NotesDocument
Dim parentdoc As notesDocument
Dim collection As NotesDocumentCollection
Dim parentdocitem As NotesItem

Dim item As NotesItem
Dim temp As Double
Dim ret As Variant
Dim view As NotesView

Dim ta As Double
Dim ts As Double
Dim trf As Double
Dim inst As Double
Dim mi As Double
Dim parentID As Variant

'SETTING THE VARIABLES
Set currentdoc = source.Document
Source.AutoReload = False
Set dbase = session.CurrentDatabase
Set responsedoc = source.Document

%REM
GETTING THE PARENT DOCUMENT'S UNIQUE ID FROM THE RESPONSE DOCUMENT AND THEN
OPENS
DOCUMENT. THE COLLECTION IS SET TO BE ALL THE RESPONSES OF THE PARENT DOCUMENT.
%END REM

parentID = responsedoc.ParentDocumentUNID
Set parentdoc = dbase.GetDocumentByUNID(ParentID)
Set collection = parentdoc.Responses

'LOOPING THROUGH ALL THE RESPONSE DOCUMENTS TO ADD THE ACTUAL SAVINGS.
WHEN DOING THIS
'IT CHECKS FOR WHETHER THE RESPONSE DOCUMENT IS A TAX ABATEMENT, TAX
SAVINGS,
'INFRASTRUCTURE, TRAINING FUNDS OR MISCELLANEOUS TYPES, SO THAT THE
CORRECT ACTUAL
'SAVINGS IN THAT PARTICULAR SECTION OF THE PARENT DOCUMENT IS POPULATED.

For count = 1 To collection.count
Set responsedoc = collection.GetNthDocument(count)
If responsedoc.TaType(0) = "Ta" Then
ta = ta + responsedoc.TaAmount(0)
End If

If responsedoc.TsType(0) = "Ts" Then
ts = ts + responsedoc.TsAmount(0)
End If

If responsedoc.TrfType(0) = "Trf" Then
trf = trf + responsedoc.TrfAmount(0)
End If

If responsedoc.InstrType(0) = "Instr" Then
inst = inst +responsedoc.InstrAmount(0)
End If

If responsedoc.MiType(0) = "Misc" Then
mi = mi + responsedoc.MiAmount(0)
End If
Next count

parentdoc.TotalAmount = ta + ts + trf + inst + mi
parentdoc.TaActAccSavings = ta
parentdoc.TsActAccSavings = ts
parentdoc.TrfActAccSavings = trf
parentdoc.InstrActAccSavings = inst
parentdoc.MiActAccSavings = mi

'SAVING THE PARENT DOCUMENT AFTER MAKING THE CHANGES.
ret = parentdoc.Save (True, False)

'REFRESHING THE VIEW TO SEE THE CHANGES MADE.
Set View = dbase.GetView("Status")
Call view.Refresh
Call workspace.viewRefresh

End Sub

This was first published in November 2000

There are Comments. Add yours.

 
TIP: Want to include a code block in your comment? Use <pre> or <code> tags around the desired text. Ex: <code>insert code</code>

REGISTER or login:

Forgot Password?
By submitting you agree to receive email from TechTarget and its partners. If you reside outside of the United States, you consent to having your personal data transferred to and processed in the United States. Privacy
Sort by: OldestNewest

Forgot Password?

No problem! Submit your e-mail address below. We'll send you an email containing your password.

Your password has been sent to:

Disclaimer: Our Tips Exchange is a forum for you to share technical advice and expertise with your peers and to learn from other enterprise IT professionals. TechTarget provides the infrastructure to facilitate this sharing of information. However, we cannot guarantee the accuracy or validity of the material submitted. You agree that your use of the Ask The Expert services and your reliance on any questions, answers, information or other materials received through this Web site is at your own risk.