Adding TimeScaleValues using VBA

D

Dustin Ventin

I know I've posted about this before, but hopefully this should be the last
time.
The answers I have been receiving mostly seem to describe how to VIEW the
data, and not CHANGE it.

Now, I have a series of records in my user-created database that looks like
this:

PROJ_ID TASK_ID ActualCost_Date Amount RES_ID
1 1 7/12/2004 $500 4
1 2 7/12/2004 $700 4
1 5 7/13/2004 $1600 4
1 5 7/14/2004 $300 4

For each task in my project, I am assigning a resource called 'Actual Cost'
(a material). Using the table above, I want to assign the Amount to the
Dates for each Task listed, under the timescaled cost.

I can already assign the 'Actual Cost' resource to the appropriate Tasks (as
listed in the table). Then I have to add the timescaled data. I am using
the code:

objAssignment.TimeScaleData("7/14/2004", "7/17/04",
pjAssignmentTimescaledCost, pjTimescaleDays)

....with objAssignment being set to the recently inserted assignment. Now, I
want to make those dates come from the database, and then use the 'Add'
method to insert timescaled cost data (also from the database):

objAssignment.TimeScaleData(rsExportData(2)), rsExportData(2)),
pjAssignmentTimeScaledCost, pjTimescaleDays).Add (1, rsExportData(3))

I started with trying to just set the date and print the number of values:

Msgbox(objAssignment.TimeScaleData(rsExportData(2)), rsExportData(2)),
pjAssignmentTimeScaledCost, pjTimescaleDays).Count)

....which works WITHOUT the references to the recordset. Project, however,
does not seem to recognize those recordset fields (from the database) as
being dates, and comes up with an error message when the code above is run.

Any ideas? Has anyone successfully done what I am trying to do? Thanks!

Dustin Ventin
(e-mail address removed)
 
R

Rod Gill

Hi,

For the dates try using cDate(rsExportData(3))

Make sure you use Unique Id's otherwise your code will fail as soon as an
early task is added or deleted, so renumbering ID numbers.

The timescaled elements are read/write so use them in the same way you read
a time slice. Simply put the time slice to the left of the = sign to edit.
You only need the Add method to Add a timeslice after the end of your date
range.

--
For VBA posts, please use the public.project.developer group.
For any version of Project use public.project
For any version of Project Server use public. project.server

Rod Gill
Project MVP
For Microsoft Project companion projects, best practices and Project VBA
development services
visit www.project-systems.co.nz/
Email rodg AT project-systems DOT co DOT nz
 
D

Dustin Ventin

I seem to have spoken too soon...I said that I had the original code working,
and it doesn't. I tried your suggestion, and it still came up with a 'type
mismatch' error. So then I started simplifying the code more and more, until
I've reaced essentially what is shown by Microsoft:

Dim objAssignment As Object 'Loop through and insert Assignments
Dim TSV As TimeScaleValue

rsAssignmentsNeeded.MoveFirst

Do Until rsAssignmentsNeeded.EOF
Set objAssignment = Nothing
Set objAssignment =
ProjApp.Application.ActiveProject.Tasks(rsAssignmentsNeeded(0)).Assignments.Add(ResourceID:=rsExportData(4).Value)
eScaleData(

rsExportData.MoveFirst
Do Until rsExportData.EOF
Set TSV =
ProjApp.Application.ActiveProject.Tasks(1).Assignments(1).TimeScaleData("7/14/04", "7/17/04", pjAssignmentTimescaledActualCost, pjTimescaleDays)

rsExportData.MoveNext
Loop
rsAssignmentsNeeded.MoveNext
Loop

When comes right down to it, this line of code should run corrently
indipendant of all the other object declorations and settings. Again, this
is essentially what Microsoft prescribes:

Set TSV =
ProjApp.Application.ActiveProject.Tasks(1).Assignments(1).TimeScaleData("7/14/04", "7/17/04", pjAssignmentTimescaledActualCost, pjTimescaleDays)

I don't even have the "TSV.Add(777,1)" line in there...yet it comes up with
'type mismatch'. What is going on? Am I missing a really big step?

Thanks!

Dustin
 
R

Rod Gill

Hi,

The code won't work because tsv refers to a single timeslice. Your
TimeScaleData statement returns data for 4 days and therefore returns a
collection of time slices. You also need to make sure that the date range is
teh same. If you specify a date range outside teh task's scheduled date
range there time slice doesn't exist. The following Proejct VBA code works
for me (assumes task 1 has an assignment):

Sub test()
Dim tsv As TimeScaleValues
Set tsv = ActiveProject.Tasks(1).Assignments(1).TimeScaleData _
(ActiveProject.Tasks(1).Start, ActiveProject.Tasks(1).Finish,
pjAssignmentTimescaledActualCost, pjTimescaleDays)
tsv(1).Value = 100
Set tsv = Nothing
End Sub


--
For VBA posts, please use the public.project.developer group.
For any version of Project use public.project
For any version of Project Server use public. project.server

Rod Gill
Project MVP
For Microsoft Project companion projects, best practices and Project VBA
development services
visit www.project-systems.co.nz/
Email rodg AT project-systems DOT co DOT nz
 
D

Dustin Ventin

I copied and pasted that code directly into Project, and it came up with the
same error as Access: "The Argument Value is Not Valid".

My Project has about half a dozen (test) tasks, and all of them have
assignments. The code specifies the range directly from the assignment via
coding, so the time slice is correct.

Now, am I severely retarded here, or is there something serious I'm missing?
Thank you so much for taking so much time to hand-hold me through this. I
realize this is probably as much of an aggrivation for you as it is for me.

Thanks!

Dustin Ventin
 
D

Dustin Ventin

My mistake. I had to assign it to work instead of Actual Cost. I fugured it
out myself!

Thanks (in advance for next time!)

Dustin
 

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