Home > Mobile >  How to retrieve the Custom Text (Assignment) Field value based on a Custom Number value in MS Projec
How to retrieve the Custom Text (Assignment) Field value based on a Custom Number value in MS Projec

Time:12-14

I can get to the values I am after by hardcoding, for example assignment.Text8 but can't get it to work when I create a variable and try to include it like: "if i = 8 then show me what is in assignment.Texti" Could be a syntax thing but can't figure it out.

Sub TransferAsgnTextX_to_AsgnTCC_viaNumberedMeans()
Dim t As Task
Dim a As Assignment
Dim nr, i As Integer
i = 1
For Each t In ActiveProject.Tasks
    nr = ActiveProject.Tasks(i).Number1
    If nr > 0 Then
    For Each a In t.Assignments
        Select Case a.ResourceName
        Case "Productivity"
            a.Units = "a.Text" & nr
        End Select
    Next a
    End If
    i = i   1
Next t
End Sub

Above code gives a run-time error 1101, but if I hardcoded say a.Units = a.Text8 then the code runs. But I want to find the custom text field based on the (separate) custom number.

CodePudding user response:

Stephen, if I follow what you are trying to do, you want to change the assignment units for the "Productivity" resource to whatever value is in the Task Number1 field. If so then just do that, i.e. a.Units = nr

CodePudding user response:

For the Assignment object, there is no way around getting properties other than accessing them directly. So the solution is to use a Select Case statement.

FWIW this would be much simpler if the values were stored at the task level as the Task object offers the GetField method that takes a field ID parameter and returns the variable field value. See I can't access columns in MS Project VSTO Add-In and Can FieldNameToFieldConstant be used with the TaskDependency Object for examples.

  • Related