How to use VBA to set Custom Enterpise Project Field value?

H

hale

Hi all:
I want to Use VBA to save value into Custom Enterprise Project Text1 and
Custom Enterprise Project Text1 when Project Publish.

Private Sub Project_BeforeSave(ByVal pj As Project)
Transfer_Task_Codes
End Sub

Sub Transfer_Task_Codes()
Dim tskT As Task
Dim rscR As Resource
Dim asnA As Assignment
Dim strResource As String
Dim strReqDep As String
Dim nbItems As Integer

On Error GoTo ErrorHandler
On Error Resume Next

If Application.Projects.Count > 0 Then
If ActiveProject.Tasks.Count > 0 Then
For Each tskT In ActiveProject.Tasks
If Not (tskT Is Nothing) Then
nbItems = tskT.Assignments.Count
If nbItems > 0 Then
For i = 1 To nbItems

'tskT.Assignments.Item(i).EnterpriseResourceOutlineCode28 =
tskT.EnterpriseOutlineCode1

'tskT.Assignments.Item(i).EnterpriseResourceOutlineCode29 =
tskT.EnterpriseOutlineCode2
If InStr(strReqDep,
CStr(tskT.EnterpriseOutlineCode1)) < 1 Then
If strReqDep = "" Then
strReqDep = strReqDep &
tskT.EnterpriseOutlineCode1
Else
strReqDep = strReqDep & "," &
tskT.EnterpriseOutlineCode1
End If
End If
If InStr(strResource,
CStr(tskT.Assignments.Item(i).ResourceName)) < 1 Then
If strResource = "" Then
strResource = strResource &
tskT.Assignments.Item(i).ResourceName
Else
Debug.Print strResource
strResource = strResource & "," &
tskT.Assignments.Item(i).ResourceName
End If
End If
Next i
End If
End If
Next tskT
Application.SetField pjCustomProjectEnterpriseText1, strReqDep
Application.SetField pjCustomProjectEnterpriseText2, strResource
End If
End If

Exit Sub
ErrorHandler:
MsgBox Err.Description & Chr(13) & "In Task: " & tskT.ID & Chr(13) & "In
Assignment: " & asnA.UniqueID, vbCritical, "Code Transfer Error"
Resume Next
End Sub

But I am not success.
Thank you for any help!

hale
 
K

Kevin Flanagan

I am not sure why you want to do that. If you have
defined Custom Enterprise Project Text1 in the global and
have filled it in under Project Information, just saving
the file to Project Server will do that automatically for
you. If you really need to do this, then you would need
to create a database connection and place the data in the
MSP_TEXT_FIELDS table in SQL Server in the ProjectServer
database.

Kevin
-----Original Message-----
Hi all:
I want to Use VBA to save value into Custom Enterprise Project Text1 and
Custom Enterprise Project Text1 when Project Publish.

Private Sub Project_BeforeSave(ByVal pj As Project)
Transfer_Task_Codes
End Sub

Sub Transfer_Task_Codes()
Dim tskT As Task
Dim rscR As Resource
Dim asnA As Assignment
Dim strResource As String
Dim strReqDep As String
Dim nbItems As Integer

On Error GoTo ErrorHandler
On Error Resume Next

If Application.Projects.Count > 0 Then
If ActiveProject.Tasks.Count > 0 Then
For Each tskT In ActiveProject.Tasks
If Not (tskT Is Nothing) Then
nbItems = tskT.Assignments.Count
If nbItems > 0 Then
For i = 1 To nbItems

'tskT.Assignments.Item
(i).EnterpriseResourceOutlineCode28 =
tskT.EnterpriseOutlineCode1

'tskT.Assignments.Item
(i).EnterpriseResourceOutlineCode29 =
tskT.EnterpriseOutlineCode2
If InStr(strReqDep,
CStr(tskT.EnterpriseOutlineCode1)) < 1 Then
If strReqDep = "" Then
strReqDep = strReqDep &
tskT.EnterpriseOutlineCode1
Else
strReqDep = strReqDep & "," &
tskT.EnterpriseOutlineCode1
End If
End If
If InStr(strResource,
CStr(tskT.Assignments.Item(i).ResourceName)) < 1 Then
If strResource = "" Then
strResource = strResource &
tskT.Assignments.Item(i).ResourceName
Else
Debug.Print strResource
strResource = strResource & "," &
tskT.Assignments.Item(i).ResourceName
End If
End If
Next i
End If
End If
Next tskT
Application.SetField
pjCustomProjectEnterpriseText1, strReqDep
Application.SetField
pjCustomProjectEnterpriseText2, strResource
 
B

Bill Olford

To get at the Enterprise Project Fields, use GetField & SetField on the
Project Summary Task. For example, to get & set Enterprise Project Text1,
use:

strSomeValue =
ActiveProject.ProjectSummaryTask.GetField(pjTaskEnterpriseProjectText1)

ActiveProject.ProjectSummaryTask.SetField pjTaskEnterpriseProjectText1,
"Some Value"

For more info, see GetField & SetField help info in Project 2002, please
also refer to the PJREAD10.HTM file.
 

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