Assigning a string value to Tasks(x).Text11 field

J

jennifer.lyon

Not sure what I am doing wrong (I realize the overall code is not the
cleanest in the world...esp. in terms of how I am accessing
"ActiveProject.."

Anyways, I am getting a Run-Time Error 1101 "The Argument Value is not
Valid".

What I'm doing is a simple scan of the list of resources for each task
in a project and building a formatted text string of the resources that
includes the resource UID, e.g. "[5]John.Jones, [34]James.Doe,
[234]Jim.Smith"

Then I want to assign that formatted string to the Text11 field within
the Tasks object, and the code is dying on the assignment statement.

Immediately before the attempt to perform the assignment, the
debug.print statement shows that the variable for the formatted string
does indeed have data in it.

The offending line of code is...

ActiveProject.Tasks(CurrRow).Text11 = FormatResourceNames


The overall code segment is: (mind the wrapping from google)


Sub CopyResourceNamestoText11()


Dim CurrRow As Long
Dim NumTasks As Long, NumResources As Long
Dim CurrResourceName As String, FormatResourceNames As String,
TempString As String, CurrResource As String
Dim CurrResourceUID As String


NumTasks = ActiveProject.NumberOfTasks
For CurrRow = 1 To NumTasks
NumResources = ActiveProject.Tasks(CurrRow).Resources.Count
If NumResources > 0 Then 'Theres at least 1 resource assigned
to the current task
Debug.Print "This Task has " & NumResources & " Resources
assigned."
FormatResourceNames = ""
For ICount = 1 To NumResources
CurrResourceName =
ActiveProject.Tasks(CurrRow).Resources(ICount).Name
CurrResourceUID =
ActiveProject.Resources(CurrResourceName).UniqueID
FormatResourceNames = FormatResourceNames & "[" &
CurrResourceUID & "]" & CurrResourceName & ", "
Next ICount
Debug.Print FormatResourceNames
ActiveProject.Tasks(CurrRow).Text11 = FormatResourceNames

End If
Next CurrRow

End Sub
 
J

jennifer.lyon

After doing a bit more reading, I made the code somewhat more elegant,
but still getting the same error... on the line

tS(CurrRow).Text11 = FormatResourceNames
-----

Sub CopyResourceNamestoText11()

Dim CurrRow As Long
Dim NumTasks As Long, NumResources As Long
Dim CurrResourceName As String, FormatResourceNames As String,
TempString As String, CurrResource As String
Dim CurrResourceUID As String
Dim tS As Tasks
Dim tRes As Resources


Set tS = ActiveProject.Tasks
Set tRes = ActiveProject.Resources
NumTasks = tS.Count
For CurrRow = 1 To NumTasks
NumResources = tS(CurrRow).Resources.Count
If NumResources > 0 Then 'Theres at least 1 resource assigned
to the current task
Debug.Print "This Task has " & NumResources & " Resources
assigned."
FormatResourceNames = ""
For ICount = 1 To NumResources
CurrResourceName = tS(CurrRow).Resources(ICount).Name
CurrResourceUID = tRes(CurrResourceName).UniqueID
FormatResourceNames = FormatResourceNames & "[" &
CurrResourceUID & "]" & CurrResourceName & ", "
Next ICount
Debug.Print FormatResourceNames
tS(CurrRow).Text11 = FormatResourceNames

End If
Next CurrRow

End Sub
 
J

jennifer.lyon

Thanks. I did get it to work (and tweaked the code some more in the
process). I will add the error checking on the formatted field before
I do the assignment.

end result was to do the assignment statement thus:

If Not t Is Nothing Then
SetTaskField Field:="Text11",
Value:=FormatResourceNames, TaskID:=t.ID
End If
 

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