Cant add assignment

M

MrHarakiri

I´ve got a strange problem. I tried to add a assignemnt using a sub, but i
got a error 1101. So i did it from MS Project (activity information?) and
it worked fine. Then i deleted the assignemnt and tried to do it from the Sub
and then it worked! What could be the problem? Any ideas?


Sub test()
Dim tsk As Task
Dim res As Resource
Dim ass As Assignment
Set tsk = ActiveProject.Tasks(4)
Set res = ActiveProject.Resources(201)
Set ass = tsk.Assignments.Add(tsk.ID, res.ID, "1")
ass.Delete
End Sub
 
J

John

MrHarakiri said:
I´ve got a strange problem. I tried to add a assignemnt using a sub, but i
got a error 1101. So i did it from MS Project (activity information?) and
it worked fine. Then i deleted the assignemnt and tried to do it from the Sub
and then it worked! What could be the problem? Any ideas?


Sub test()
Dim tsk As Task
Dim res As Resource
Dim ass As Assignment
Set tsk = ActiveProject.Tasks(4)
Set res = ActiveProject.Resources(201)
Set ass = tsk.Assignments.Add(tsk.ID, res.ID, "1")
ass.Delete
End Sub

MrHarakiri,
I assume the sub you are showing is the one that doesn't work although I
don't understand the "delete" statement at the end. I thought you wanted
to add an assignment?

If the goal here is to add Resource 201 as an assignment for Task 4 then
the following single line will do the trick:
ActiveProject.Tasks(4).Assignments.Add ResourceID:=201

Hope this helps.
John
Project MVP
 

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