if i run project2010+VBA code on other computer then fire runtime error 91 RRS feed

  • Question

  • Hi All,

    I have facing runtime error 91 and Automation error Exception occured issues if i run the following code on the other machine.

    ErrorLine: If ((t.Flag3 = True) And (Val(t.Text20) > 0)) And (t.Text7 = "CR") Then

    Public Sub Items()
        Dim t As Task
        Dim taskid As Integer
        Dim erg As Long
        Dim errmsg As String
        Dim proj As String
        Dim tmp As String
        Dim typ As String
        Dim parentTaskID As Long
        Dim createCRInCreation As Boolean
        parentTaskID = -1
        ' Check if successfully connected to MKS
        If Not MKS_Connector.connect2MKS() Then
            Exit Sub
        End If
            ' walk through all tasks
            If (MsgBox("Create CR in State - Creation and Moduletest", vbOKCancel) = vbOK) Then
                createCRInCreation = True
                createCRInCreation = False
            End If
            For Each t In ActiveProject.Tasks
                If (t Is Nothing) Then
                    ' skip this
                    Application.StatusBar = "Processing Task " &
                    erg = 0
                    ' check whether this is a container task
                    If (taskHasChildren(t)) Then
                        ' this is a container Task
                        ' check if it has an MKS IM ID
                        If t.Flag1 = True Then
                            Dim tmpID As Long
                            Dim ParentTaskPath
                            If (t.Text20 <> "") Then
                                tmpID = t.Text20
                                tmpID = 0
                            End If
                            If (tmpID > 0) Then
                                ' set container task id to mksID for later use in Issue creation
                                parentTaskID = t.Text20
                                erg = 0
                                ' no ID available yet, so ask whether to create a container
                                erg = MsgBox("Task " & t.ID & " is a container task without an MKS IM ID. Do you want to create an MKS IM container ?", vbQuestion + vbYesNo, MKS_Header)
                                If (erg = vbYes) Then
                                    ' create container task
                                    parentTaskID = createMKSContainerTask(t)
                                    erg = parentTaskID
                                    t.Text20 = parentTaskID
                                    ' set container task id to -1 because user does not want it
                                    parentTaskID = -1
                                    erg = 0
                                End If
                            End If
                        End If
                        'only process items which have the sync with MKS flag set and which have no ID
                        If ((t.Flag1 = True) And (Not (Val(t.Text20) > 0))) Then

                            ' so as a result, the given task has no MKS IM item yet.
                            ' we have to check whether all required attributes are set properly
                            ' only then we can initiate a new MKS IM item
                            ' check for proper project assignment
                            proj = lookupProjectName(t.Text5)
                            If (proj = Defines.MKS_ERROR) Then
                                errmsg = "Project Value is not valid for task "
                                erg = -1
                                GoTo FAILURE
                            End If
                            ' check if assigned user is available
                            If (t.Resources.Count = 0) Then
                                errmsg = "MKS item can not be created because the MS Project task has no assigned user "
                                erg = -1
                                GoTo FAILURE
                            End If
                            ' check if Issue Type is available
                            typ = t.Text7
                            If ((typ <> "Task") And (typ <> "CR") And (typ <> "MoM") And (typ <> "Review")) Then
                                ' throw an error
                                errmsg = "Not clear what issue type shall be created"
                                erg = -1
                                GoTo FAILURE
                            End If
                            Select Case typ
                                Case "CR"
                                    If (MsgBox("Do you want to create a Change Request for task " &, vbYesNo, "Create MKS Items") = vbYes) Then
                                        ' Create the change request
                                        erg = createMKS_Issue_From_Task(t, Defines.CRType, createCRInCreation)
                                    End If
                                Case "Task"
                                    If (MsgBox("Do you want to create a Task for task " &, vbYesNo, "Create MKS Items") = vbYes) Then
                                        erg = createMKS_Issue_From_Task(t, Defines.TaskType)
                                    End If
                                Case "MoM"
                                    errmsg = "This code is not yet implemented in this script "
                                    erg = -1
                                    GoTo FAILURE
                                Case "Review"
                                    If (MsgBox("Do you want to create a Review Master for task " &, vbYesNo, "Create MKS Items") = vbYes) Then
                                        erg = createMKS_Issue_From_Task(t, Defines.RMType)
                                    End If
                                Case Else
                            End Select
                            ' check whether an MKS review master is already available
                            If ((taskHasChildren(t)) Or (t.Text21 <> "")) Then
                                ' do nothing
                                ' no error, so check whether to create technical review for this item
                                If (t.Flag2) Then
                                    reviewID = createMKSReviewForIssue(t, erg)
                                    If (reviewID <> -1) Then
                                        ' Make the entry
                                        t.Text21 = reviewID
                                        tmp = MsgBox("Error while creating the review master for task " & t.ID & " : Message :" & erg, vbExclamation, MKS_Header)
                                    End If
                                End If
                            End If
                            erg = 0
                        End If
                    End If
                    ' check the result
                    If (erg = -1) Then
                        ' an error accured, so give a message to the user
                        taskid = t.ID
                        tmp = MsgBox(errmsg & taskid, vbExclamation, MKS_Header)
                        ' Relate this task to the parent task
                        If (erg > 0) Then
                            ' check whether the parent task exists and it has a valid MKS ID
                            If (taskHasParent(t)) Then
                                ' Parent exists
                                If (t.OutlineParent.Text20 <> "") Then
                                    parentTaskID = t.OutlineParent.Text20
                                    If (parentTaskID > 0) Then
                                        bDone = addMKSRelationship(erg, parentTaskID)
                                        If (bDone = False) Then
                                            erg = MsgBox("Not possible to create relationship between " & parentTaskID & " and " & t.Text20, vbExclamation + vbOKOnly, MKS_Header)
                                        End If
                                    End If
                                End If
                            End If
                        End If
                    End If
                End If
            Next t
           For Each t In ActiveProject.Tasks
           If ((t.Flag3 = True) And (Val(t.Text20) > 0)) And (t.Text7 = "CR") Then
           End If
        MsgBox "Done"
    End Sub

    Thursday, April 18, 2013 5:06 AM


All replies

  • Hi Mahi23,

    Thank you for posting in the MSDN Forum.

    Since your issue is about Project programming, I've moved it to Project Customization and Programming forum for better support.

    Thank you for your understanding.

    Best regards,

    Quist Zhang [MSFT]
    MSDN Community Support | Feedback to us
    Develop and promote your apps in Windows Store
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    Friday, April 19, 2013 1:29 PM
  • Hi,

    In your second For each loop you do not exclude the blank (i.e. "Nothing") tasks

    Insert if not t is nothing then, and another end if before next.


    Friday, April 19, 2013 1:50 PM
  • Check you've got the same set of references on each machine.

    On both machines, open up the Visual Basic Editor, then from the dropdown menu select Tools > References...

    The Automation Error you're seeing can be caused by having the wrong references, or the wrong version of DLL which are referred to from this screen.

    Another cause I'm aware of, if you try to run a bit of code while another routine is still running (i.e. looking in the VBE, if the play button is disabled, and the title of the window is suffixed with [break]), you will also see this error.

    Hope this is helpful,

    Monday, April 22, 2013 1:05 PM
  • Hi Mr. Jan De,

    Many Many thanks for this solution My issue has solved.

    Thanks one again..

    Tuesday, April 23, 2013 12:15 PM