TimeScaleValue

J

John

I am trying to add hours worked to an assignment.

I copied and pasted the following code directly from the Help file:

Dim TSV As TimeScaleValues

Set TSV = ActiveCell.Resource.TimeScaleData("10/7/02", "10/11/02",
TimescaleUnit:=pjTimescaleDays)
TSV.Add 480, 2
Dim TSV As TimeScaleValues

Set TSV = ActiveCell.Resource.TimeScaleData("10/7/02", "10/11/02",
TimescaleUnit:=pjTimescaleDays)
TSV.Add 480, 2

When I run the code I get Run-time error 1101: The argument is not valid.

Can anyone tell me what I am doing wrong?

Thanks for your help

John
 
J

Jan De Messemaeker

Hi,

On which of the two statements do you get the error?
(It is in yellow when you hit debug)
I suspoect it is the first one.
What is the activecell? Does it have a resource?
Which view is active?
HTH
 
J

John

Thanks for your prompt response.

I am getting the error on TSV.Add 480, 2.
The Resource Usage view is active .
I have tried having the Unique ID and Resource Name be the active cell. I
get the same message regardless of which cell is active.
 
J

Jan De Messemaeker

Hello John,

It took me a lot af trials and going through the deepest despair before
understanding this one.
The example is conceptually impossible.
If you insert a new TSV into a resource's, and the resource has several
assignments it is supposed to work on, to whoch assignment would the Project
attach the new work? And would ALL assignments be shifted?
The simple truth seems to me you cannot us ethe add method for resource's
TSVs.

The following works perfectly (active view is a task view e.g. gantt chart)
:

set tsv=activecell.tasks.assignments(1).timescalevalues(date1,date2,
etcetera..
tsv.add 480,2

Hope this helps,
 
Joined
Nov 3, 2019
Messages
2
Reaction score
0
I want to populate actual work on a resource assignment.
Below is code written to just try the concept. It assigns 8 hours of actual work to each day defined for a resource assignment. The statement: "TSV.Value = 480" results in Error 1101 - 'Application-defined or object-defined error'

Sub TestTSV()
Dim ProjTasts As Tasks
Dim MyTask As Task
Dim TaskDate As Date, TaskTo As Date
Dim TaskAssignments As Assignments
Dim MyAssignment As Assignment
Dim Tsvs As TimeScaleValues
Dim TSV As TimeScaleValue
Set ProjTasks = ActiveProject.Tasks
' find the task
For Each projtask In ProjTasks
'these if statements step through all tasks in the project
TaskDate = projtask.Start
TaskTo = projtask.Finish
If Not (projtask Is Nothing) Then
If projtask.Summary = False Then
' find the assignment
Set TaskAssignments = projtask.Assignments
For Each MyAssignment In TaskAssignments
Set Tsvs = MyAssignment.TimeScaleData(TaskDate, TaskTo, Type:=pjResourceTimescaledActualWork, TimeScaleUnit:=pjTimescaleDays)
For Each TSV In Tsvs
Debug.Print TSV.StartDate, TSV.Value, TSV.EndDate, TSV.Parent, TSV.Index
TSV.Value = 480
Next TSV
Next MyAssignment
End If
End If
Next projtask
End Sub
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top