1
votes

I want to set flag type enterprise custom field at the task level to True/False Or Yes/No. May I know the syntax for the same in VBA.

The MSDN says:

projectField = FieldNameToFieldConstant("TestEntProjText", pjProject)

ActiveProject.ProjectSummaryTask.SetField FieldID:=projectField, Value:="This is a new value." 

where Value is a string. But in my case I want it to be a boolean value.

2

2 Answers

0
votes

The SetField method always takes a string value but can be used to set any field. Use "Yes" and "No" to set Boolean values.

The related method GetField returns a field value as it is displayed in the table view and thus always returns a string.

0
votes

Sub setEnterpriseFlag()

Dim myTask As Task
Set myTask = ActiveProject.Tasks.Item(1)

Debug.Print myTask.GetField(pjTaskEnterpriseFlag1)
Debug.Print myTask.GetField(pjTaskEnterpriseFlag2)

myTask.SetField pjTaskEnterpriseFlag1, boolToStr_forSetField(True)
myTask.SetField pjTaskEnterpriseFlag2, boolToStr_forSetField(False)

Debug.Print myTask.GetField(pjTaskEnterpriseFlag1)
Debug.Print myTask.GetField(pjTaskEnterpriseFlag2)

End Sub

'Unfortunately task.SetField and task.GetField deal only with strings. An easy 'way to manage this would be to use a simple wrapper function. Function boolToStr_forSetField(boolVal As Boolean) As String If boolVal Then boolToStr_forSetField = "Yes" Else boolToStr_forSetField = "No" End If End Function