Results 1 to 2 of 2
  1. #1
    wmj
    Guest

    Referencing Fields Programatically (Project 2000)

    I need to be able to change references to task fields that are being used on the fly (as a result of user input) and I don't want to have to hard code every possible option.

    For example, How do I make the reference to ".Duration1" etc in the following code via VBA assuming that I have the field name in a string variable called strFieldName.

    For Each oTask In ActiveSelection.Tasks
    If Not oTask.Summary Then
    oTask.Duration1 = oTask.Duration3 * oMinPercent
    oTask.Duration2 = oTask.Duration3 * oMaxPercent
    End If
    Next oTask

    Thanks in advance.

    Warren James

    PS I have cross-posted to the Project forum as I wasn't sure which was the best/right place to put this.

  2. Get our unique weekly Newsletter with tips and techniques, how to's and critical updates on Windows 7, Windows 8, Windows XP, Firefox, Internet Explorer, Google, etc. Join our 480,000 subscribers!

    Excel 2013: The Missing Manual

    + Get this BONUS — free!

    Get the most of Excel! Learn about new features, basics of creating a new spreadsheet and using the infamous Ribbon in the first chapter of Excel 2013: The Missing Manual - Subscribe and download Chapter 1 for free!

  3. #2
    Platinum Lounger
    Join Date
    Dec 2000
    Location
    Queanbeyan, New South Wales, Australia
    Posts
    3,730
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Referencing Fields Programatically (Project 2000)

    Warren,

    While I don't know about project, this is how I might code accessing elements in a collection- where I want to access other elements in the collection- in Word:<pre>For i = 1 To ActiveDocument.FormFields.Count
    Set ff = ActiveDocument.FormFields(i)
    If ff.Result = "A" Then
    ActiveDocument.FormFields(i + 1).Result = "B"
    ActiveDocument.FormFields(i + 2).Result = "C"
    End If
    Next</pre>


    It is also possible to use the "Next" property (if applicable):<pre>For Each ff In ActiveDocument.FormFields
    If ff.Result = "A" Then
    ff.Next.Result = "B"
    ff.Next.Next.Result = "C"
    End If
    Next</pre>

    Subway Belconnen- home of the Signboard to make you smile. Get (almost) daily updates- follow SubwayBelconnen on Twitter.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •