Using SetField and GetField Methods to Assign and Retrieve Data from Project RRS feed

  • Question

  • Am I misunderstanding these Task Object Methods?  I initially interpreted Setfield to be sort of a complimentary method to Getfield.  A few weeks ago I was attempting to pull information from a project field, without specifying ahead of time which project field, and I was advised to use something similar to this:

    XYZ = ActiveSelection.Tasks(1).GetField.FieldNameToFieldConstant("Some Field")

    For Reference here is that thread:

    To recap: at some point during the execution of my macro I discover/determine which field I want, and then convert that field name to a field constant and use the GetField method to grab the value of the field and assign it to variable XYZ.  Is the opposite possible?  Can I, during the execution of my macro, discover/determine which field I want, and then use the SetField method to assign the value of a variable (XYZ) to that field?

    ActiveSelection.Tasks(1).SetField.FieldNameToFieldConstant("Some Field") = XYZ

    I did try to research this before I asked this question and I know the actual format for SetField is a little bit different than Getfield.  i.e. expression.SetField(FieldID, Value) Where "Value" is a required.  Would "Value" be my variable XYZ?  I tried using this format i.e.

    ActiveSelection.Tasks(1).SetField.FieldNameToFieldConstant("Some Field", XYZ)

    But, as you can imagine, this won't compile because an "=" is expected.  Can anyone help me to resolve this?


    Friday, August 12, 2011 2:35 PM


All replies

  • Hi,

    Haven't tried this but it looks like a better guess is

    activeselection.tasks(1).setfield(fieldnametofieldconstant("Some Field"),XYZ)

    which respects the syntax


    Friday, August 12, 2011 3:05 PM
  • Oops... you're right, there should be a parenthesis there.  It should be:

    Activeselection.tasks(1).setfield(fieldnametofieldconstant("Some Field"),XYZ)

    instead of

    ActiveSelection.Tasks(1).SetField.FieldNameToFieldConstant("Some Field", XYZ)

    It still results in an error because it's still expecting an "=" as part of the expression. Am I at least correct in the belief that SetField allows me to assign values to a field entry?  Is it possible to assign values to field entries one at a time using the SetField method, in the same way it's possible to get the values from a field one at a time using Getfield?

    Saturday, August 13, 2011 2:57 PM
  • Hi B Fennell,

    maybe yous should use :

    CALL Activeselection.tasks(1).setfield(fieldnametofieldconstant("Some Field"),XYZ)

    I hope this can help you,

    Best regards

    PAolo O.

    Saturday, August 13, 2011 6:06 PM
  • No need for the CALL. I use the following regularly where Tsk is a Task variable


    Yes you can set one field at a time.

    Rod Gill

    The one and only Project VBA Book Rod Gill Project Management
    Saturday, August 13, 2011 9:30 PM
  • I appreciate everyone's suggestions but I am still struggling to get this to work. 


    Maybe I can get further along if I try to reverse engineer.  Can anyone write me a short routine using:




    that would put the word "WORK" in a Text field? 

    Sunday, August 14, 2011 5:13 AM
  • Tsk.SetField application.FieldNameToFieldConstant("Text1"),"Work"

    Sorry, shouldn't have had teh extra () in.

    Rod Gill

    The one and only Project VBA Book Rod Gill Project Management
    • Marked as answer by B Fennell Monday, August 15, 2011 10:34 PM
    Sunday, August 14, 2011 8:07 AM
  • That did the trick.  I figured if I could just see it work one time, I could probably modify it to do what I needed it to do... and that's exactly what happened.  Thanks again.
    Monday, August 15, 2011 10:34 PM