Separating finding the field code from setting the value might help isolate the error:
Dim prTask As Task
Dim fldCode As Long
fldCode = FieldNameToFieldConstant("EntCustField")
For Each prTask In prProject.Tasks
prTask.SetField fldCode, "value"
Next