Application.FieldNameToFieldConstant method (Project)
Returns a Long value for a local custom field or an enterprise custom field name.
Syntax
expression. FieldNameToFieldConstant
( _FieldName_
, _FieldType_
)
expression A variable that represents an Application object.
Parameters
Name | Required/Optional | Data type | Description |
---|---|---|---|
FieldName | Required | String | The name of the local or enterprise custom field. |
FieldType | Optional | Long | The type of field. Can be one of the following PjFieldType constants: pjProject, pjResource, or pjTask. The default value is pjTask. |
Return value
Long
Remarks
If the FieldName argument is a local custom field, the returned value can be a PjField constant. If FieldName is an enterprise custom field, the returned value does not match a PjField constant because there can be an unlimited number of enterprise custom fields.
Note
For usability and performance reasons, the number of enterprise custom fields should be limited to a few hundred or less.
You can access project custom fields through the ProjectSummaryTask property.
Example
The following example shows the difference between the FieldNameToFieldConstant method and the FieldConstantToFieldName method:
To use the example, use Project Web App to create an enterprise project text custom field named TestEntProjText.
Restart Project with a Project Server profile so that it includes the new custom field.
Create a project with some value for the TestEntProjText field, by using the Project Information dialog box.
The TestEnterpriseProjectCF macro uses the FieldNameToFieldConstant method to find the projectField number, for example, 190873618.
The macro shows the number and text value in a message box, by using the GetField method.
The macro gets the field name by using the FieldConstantToFieldName method, sets a new value by using the SetField method, and then shows the field name and new value in another message box.
Sub TestEnterpriseProjectCF()
Dim projectField As Long
Dim projectFieldName As String
Dim message As String
projectField = FieldNameToFieldConstant("TestEntProjText", pjProject)
' Show the enterprise project field number and old value.
message = "Enterprise project field number: " & projectField & vbCrLf
MsgBox message & ActiveProject.ProjectSummaryTask.GetField(projectField)
ActiveProject.ProjectSummaryTask.SetField FieldID:=projectField, Value:="This is a new value."
' For a demonstration, show the field name from the field number, and verify the new value.
projectFieldName = FieldConstantToFieldName(projectField)
message = "New value for field: " & projectFieldName & vbCrLf
MsgBox message & ActiveProject.ProjectSummaryTask.GetField(projectField)
End Sub
Support and feedback
Have questions or feedback about Office VBA or this documentation? Please see Office VBA support and feedback for guidance about the ways you can receive support and provide feedback.
피드백
https://aka.ms/ContentUserFeedback
출시 예정: 2024년 내내 콘텐츠에 대한 피드백 메커니즘으로 GitHub 문제를 단계적으로 폐지하고 이를 새로운 피드백 시스템으로 바꿀 예정입니다. 자세한 내용은 다음을 참조하세요.다음에 대한 사용자 의견 제출 및 보기