I am trying to loop through Areas, Branches and their values, but it seems the select statement is activated only once, and afterwards the selected value remains the same, even after using the clear method.
What am I doing wrong?
thnx in advance.
sub calculateAreasGoals dim a(5) Set val=ActiveDocument.Fields("Areas").GetPossibleValues 'ActiveDocument.ClearAll False For i=0 to val.Count-1 ActiveDocument.Fields("Areas").Select val.Item(i).Text a(i) = loopBranches 'Activedocument.ClearAll next 'i set val=nothing Activedocument.Fields("Areas").Clear ActiveDocument.ClearAll False end sub
function getGoal() set val_1 = nothing Activedocument.Fields("NISGOAL").clear Set val_1=ActiveDocument.Fields("NISGOAL").GetPossibleValues ActiveDocument.Fields("NISGOAL").Select val_1.Item(0).Text Activedocument.Fields("NISGOAL").Unlock Activedocument.Fields("NISGOAL").Clear tmp = val_1.Item(0).Text set val_1 = nothing getGoal = tmp end function
function loopBranches Set branch=ActiveDocument.Fields("BRANCHNAME").GetPossibleValues Accumulator=0 for i = 0 to branch.Count-1 set vals=nothing tmp = branch.Item(i).Text ActiveDocument.Fields("BRANCHNAME").Unlock ActiveDocument.Fields("BRANCHNAME").Clear ActiveDocument.Fields("BRANCHNAME").Select branch.Item(i).Text set vals=ActiveDocument.Fields("BRANCHNAME").GetSelectedValues Accumulator=Accumulator+getGoal ActiveDocument.Fields("BRANCHNAME").Clear next 'i set branch=nothing ActiveDocument.Fields("BRANCHNAME").Unlock ActiveDocument.Fields("BRANCHNAME").Clear loopBranches = Accumulator end function