none
Project 2010 VBA / Custom Button/ ToggleAssignments in pjResourceUsage/ pjTaskUsage-Screen RRS feed

  • Question

  • Dear Forum,

    i want to implement a button in a custom ribbon that provides the functionality of the application-method ToggleAssignments (in a usage-view the button collapses/ shows all assignment-lines of the current selection).

    In this context i do have two questions:

    1. The button will be located in a custom-ribbon, and i would like to enable/ disable the button according to the current screen-type: only for pjResourceUsage and pjTaskUsage-Views the button shall be enabled. Up to now my first approach for this screencheck would be something like:

    ------------------------------------------------------- 

    Dim v As View
    Dim strReturn As String
    strReturn = "false"

    For Each v In ActiveProject.Views
        If ActiveProject.CurrentView = v Then
            If v.Screen = pjResourceUsage Then
                strReturn = "true"
            End If
        End If
    Next v

    -------------------------------------------------------

    The function gives a string with a written boolean value which will be uses in the SetCustomUI-method to build the new ribbon.

    Do you see a better approach to check for the current screentype?

    2. My second question focuses on the use of the ToggleAssignments-Method

    in a project with no assignments the method crashes -> before calling the method i have to check, if the current project has zero assignments. Is there a more efficient way to check this than to loop through all resources and all their assignments with an "exit for" on countAssignments > 0?

    Thank you in advance and best regards,

    Phil

     

     


    • Edited by Phil Bertram Wednesday, December 7, 2011 6:55 PM
    Wednesday, December 7, 2011 3:09 PM

Answers

  • I would use:

    Dim UsageView As Boolean
        If InStr(ActiveProject.CurrentView, "Usage") > 0 Then
            UsageView = True
        Else
            UsageView = False
        End If

    and

    Dim Res As Resource
    Dim HaveAssignments As Boolean
        For Each Res In ActiveProject.Resources
            If Res.Assignments.Count > 0 Then
                HaveAssignments = True
                Exit For
            End If
        Next Res

    Rod Gill

    The one and only Project VBA Book Rod Gill Project Management
    • Marked as answer by Phil Bertram Thursday, December 8, 2011 11:54 AM
    Wednesday, December 7, 2011 8:53 PM
    Moderator

All replies

  • I would use:

    Dim UsageView As Boolean
        If InStr(ActiveProject.CurrentView, "Usage") > 0 Then
            UsageView = True
        Else
            UsageView = False
        End If

    and

    Dim Res As Resource
    Dim HaveAssignments As Boolean
        For Each Res In ActiveProject.Resources
            If Res.Assignments.Count > 0 Then
                HaveAssignments = True
                Exit For
            End If
        Next Res

    Rod Gill

    The one and only Project VBA Book Rod Gill Project Management
    • Marked as answer by Phil Bertram Thursday, December 8, 2011 11:54 AM
    Wednesday, December 7, 2011 8:53 PM
    Moderator
  • Hi Rod,

    The first approach implies that the name of the view indicates the type, but i'm using custom views with custom names, and i would like to provide the functionality of the ToggleAssignments-Button to all views of the usage type.

    The second approach clearly improves my draft, because by using assignments.count i don't need to loop through all the assignments and to count them.

    Thank you for you help and best regards

    Phil 

    Thursday, December 8, 2011 11:54 AM