Resource.SetField 方法 (Project)

设置指定的资源自定义域的值。

语法

expression. SetField( _FieldID_, _Value_ )

表达 一个代表 Resource 对象的变量。

参数

名称 必需/可选 数据类型 说明
FieldID 必需 Long 对于本地自定义字段,可以是资源自定义域的 PjField 常量之一。 对于企业自定义字段,使用 FieldNameToFieldConstant 方法来获取 FieldID。
Value 必需 String 该域的值。

示例

下面的示例演示如何使用 SetField 方法和 GetField 方法在 FieldNameToFieldConstantFieldConstantToFieldName 方法 资源 对象访问企业资源自定义域。

  1. 若要使用本示例,请使用 Project Web App 创建一个企业资源文本自定义域,例如名为 TestEntResText 的域。

  2. 以使其包括新的自定义字段,使用 Project Server 配置文件,重新启动项目专业人员。

  3. 创建项目,从企业资源建立工作组,然后为第一个任务分配资源。

  4. TestEnterpriseResourceCF 宏,使用 FieldNameToFieldConstant 方法来找到 resourceField 号,例如,205553667。

  5. 宏在消息框中,通过使用 GetField 方法将显示编号和文本值。

  6. 该宏使用 SetField 方法设置的自定义字段的新值。

  7. 该宏使用 FieldConstantToFieldName 方法,获取的字段名称,然后在另一个消息框中显示的字段名称和新值。

Sub TestEnterpriseResourceCF() 
    Dim resourceField As Long 
    Dim resourceFieldName As String 
    Dim resourceFieldValue As String 
    Dim message As String 
 
    resourceField = FieldNameToFieldConstant("TestEntResText", pjResource) 
 
    ' Show the enterprise resource field number and old value. 
    message = "Enterprise resource field number: " & resourceField & vbCrLf 
    resourceFieldValue = ActiveProject.Tasks(1).Assignments(1).Resource.GetField(resourceField) 

    If resourceFieldValue = "" Then resourceFieldValue = "[No value]" 
    MsgBox message & "Field value: " & resourceFieldValue 
 
    ' Set a value for the enterprise resource custom field. 
    ' Use either the Resources collection or the Assignments collection 
    ' to access the resource custom field. 
    ' Here, use the Assignments collection. 
    ActiveProject.Tasks(1).Assignments(1).Resource.SetField _
        FieldID:=resourceField, Value:="This is a new value." 
 
    ' For a demonstration, get the field name from the number, 
    ' and then verify the new value. 
    resourceFieldName = FieldConstantToFieldName(resourceField) 
 
    ' Here, use the Resources collection to access the custom field. 
    resourceFieldValue = ActiveProject.Resources(1).GetField(resourceField) 
 
    message = "New value for field: " & resourceFieldName & vbCrLf 
    MsgBox message & "Field value: " & resourceFieldValue 
End Sub

有关使用本地资源自定义域的示例,请参阅 GetField 方法。

支持和反馈

有关于 Office VBA 或本文档的疑问或反馈? 请参阅 Office VBA 支持和反馈,获取有关如何接收支持和提供反馈的指南。