none
detect if a view is available RRS feed

  • Question

  • using 2007

    I need to determine if a particular view exists- IAW psuedo code:

    if MyView exists

       apply it

    else

       create it

       apply it

    endif

    I know how to create it, but I can't  seem to find the commands that detect it.

    GMAN1941

    Friday, June 29, 2012 12:33 PM

Answers

  • Hi GMAN,

    The following may be a pain to the eye of the "pure" devloper but I think it works:

    On error go to create_view

    viewapply "the view to test"

    goto itsthere

    create_view:

    ViewEditSingle ....

    itsthere:

    on error goto 0

    ___________________

    Greetings,

    Friday, June 29, 2012 7:09 PM
    Moderator

All replies

  • GMAN1941

    The following function may be of help, I've used it to check for the presence of views in a project:


    Function FindView(viewName As String) As Boolean
        Dim ctr As Integer

        FindView = False
        For ctr = 1 To Application.Views.Count
            If Application.Views(ctr).Name = viewName Then
                FindView = True
                Exit For
            End If
        Next ctr
       
    End Function

    Or an equivalent for the Global.mpt:

    Function FindGlobalView(viewName As String) As Boolean
        Dim ctr As Integer

        FindGlobalView = False
        For ctr = 1 To Application.GlobalViews.Count
            If Application.GlobalViews(ctr).Name = viewName Then
                FindGlobalView = True
                Exit For
            End If
        Next ctr
       
    End Function

    Hope this helps

    Friday, June 29, 2012 1:00 PM
  • Hi GMAN,

    The following may be a pain to the eye of the "pure" devloper but I think it works:

    On error go to create_view

    viewapply "the view to test"

    goto itsthere

    create_view:

    ViewEditSingle ....

    itsthere:

    on error goto 0

    ___________________

    Greetings,

    Friday, June 29, 2012 7:09 PM
    Moderator
  • Jan

    thanks for the input.   I made a slight adjustment to fit my circumstance - perfect solution! 

    BTW - the code i developed creates/applies a combination view with the Relationship Diagram on the bottom and a Gantt View on top.  When the user selectes a task, the immediate predecessors and successors are shown in the bottom view.  the top view will show the selected task in gantt view but not necessarily the predecessors and successors.  the macro identifies the predecessors and successors and sets a code (in text2) - then a filter is applied, data sorted, link lines displayed -  and - voila - the tasks shown in the bottom pane are now displayed in gantt form in the upper pane allowing the user to see the tasks in a time and link relationship format.

    you are welcome to the code if you are interested

    thanks again,

    GMAN1941

    Monday, July 2, 2012 1:00 PM