title: Reading and writing MS Project TimeScaleData for Resources, and Assignments
body: <p>I am pulling projected cost into Excel reports and an external db. Part of the monthly projections are to update the project overheads. So I need to accurately pull monthly cost as well as write monthly cost to the overheads tasks.</p>
  
  <p>I am having trouble understanding why would you read and write to an Assignment instead of directly to the cost Resource?</p>
  
  <p>Read the month cost by resource (simplified):</p>
  
  <pre><code>Dim tsvs as TimeScaleValues
  Dim res as Resource
  
  Do Until budgetDate &gt; ActiveProject.ProjectFinish
      For Each res In ActiveProject.Resources
          Set tsvs = res.TimeScaleData(StartDate:=budgetDate, EndDate:=budgetDate, Type:=pjResourceTimescaledCost, TimeScaleUnit:=pjTimescaleMonths, Count:=1)
          myMonthCost = Val(tsvs(1).Value)
      Next res
      budgetDate = DateAdd("m", budgetDate, 1)
  Loop
  </code></pre>
  
  <p>There is only one TimeScaleValue in tsvs (the single month) so I believe that I'm fine just referencing tsvs(1).Value instead of having to increment through the collection.</p>
  
  <p>Read month cost with assignments:</p>
  
  <pre><code>Do Until budgetDate &gt; laborFinishDate
      For Each res In ActiveProject.Resources
          Set asgts = res.Assignments
          For Each asgt In asgts
              Set tsvs = asgt.TimeScaleData(StartDate:=budgetDate, EndDate:=budgetDate, Type:=pjAssignmentTimescaledCost, TimeScaleUnit:=pjTimescaleMonths, Count:=1)
              myMonthCost = myMonthCost + Val(tsvs(1).Value)
          Next asgt
      Next res
      budgetDate = DateAdd("m", budgetDate, 1)
  Loop
  </code></pre>
  
  <p>And finally write the month overhead cost to the overhead task:</p>
  
  <pre><code>myOverhead = myMonthCost * myRate
  
  Set tsk = ActiveProject.Tasks("Overhead")
  Set tsvs = tsk.Assignments(1).TimeScaleData(StartDate:=budgetDate, EndDate:=budgetDate, Type:=pjAssignmentTimescaledCost, TimeScaleUnit:=pjTimescaleMonths)
  
  tsvs(1).Value = myOverhead
  </code></pre>
  
  <p>This method works for me but I am frustrated I cannot get it to work writing directly to the resource cost. I don't really understand why I would have to read or write to an assignment (either task or resource) instead of directly to the resource itself. Could anyone explain why one should read and write costs using assignments or if there is a better way using the resources directly?</p>
  
  <p>Thanks for your time.</p>