Quantcast
Channel: Project Customization and Programming forum
Viewing all articles
Browse latest Browse all 5347

Help with VBA for showing project resources

$
0
0

Hi all,

I have not worked with VBA before and I am trying to create a local field which holds the current project team members. The idea is to allow the PM select one of the resources as the "Task Owner" for any task in the plan. I cannot use an enterprise lookup table since I need the field to get its values per project.

So I am actually using a local lookup field as a list value. Since it will not auto-update when e.g. I add a new resource or delete an existing resource, I will bind it to an event (e.g. Calculate). What I do is copy selected values to a temp field initially, delete the lookup contents and re-populate from "Resources", then copy back previously selected values from the temp field. It doesn't work as expected in all cases. Can anyone assist please or propose an alternative way to accomplish my requirement ?

Private Sub LoadProjectTeam()

Dim r As Resources, Temp As Long, tsk As Task, counter As Long

For Each tsk In ActiveProject.Tasks
    If Not (tsk Is Nothing) Then
        tsk.Text30 = tsk.Text2   'copy selected values to the temp text30 field, text2 is a local lookup field
    End If
Next tsk

' Need to empty the lookup since new resources may have been added or existing ones have been deleted

On Error GoTo ErrorHandler1
Do While CustomFieldValueListDelete(pjCustomTaskText2, 1) = True  
Loop

' Weird, the above code not only deletes value list but also selected values in text2...

ErrorHandler1:
Resume Label1

Label1:
Set r = ActiveProject.Resources

On Error GoTo ErrorHandler2
For Temp = 1 To r.Count    'add current project resources to lookup
    If (CustomFieldValueListAdd(pjCustomTaskText2, r(Temp).Name) = False) Then
        MsgBox "Error determining project team"
End If
Next Temp

ErrorHandler2:
Resume Label2

Label2:
On Error GoTo ErrorHandler3
For Each tsk In ActiveProject.Tasks
    If Not (tsk Is Nothing) Then
        If (tsk.Text30 <> "") Then
        tsk.Text2 = tsk.Text30     'copy back from the temp field the previously selected values
        End If
    End If
Next tsk

ErrorHandler3:
Resume Next


End Sub



Viewing all articles
Browse latest Browse all 5347

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>