none
Exporting TimePhased Data to Microsoft Project RRS feed

  • Question

  • I'm trying to programmatically insert actual data into the Microsoft Project timescaled data.  The data in dsExportData looks like this:

    UProj_ID    BD_TASK_ID    ActualCost_AccountingDate    Total
    216    1    00:00.0    0
    216    1    00:00.0    500
    216    1    00:00.0    2000
    216    1    00:00.0    900
    216    1    00:00.0    -80
    216    1    00:00.0    800
    216    1    00:00.0    80000
    216    1    00:00.0    90
    216    1    00:00.0    17
    216    1    00:00.0    50
    216    1    00:00.0    240

    My code to export the data is as follows:

     Dim objAssignment As Assignment
           
            intGridRow = 0
    
            appProj.OptionsCalculation(AutoCalcCosts:=False)
    
                 Dim tsvs As TimeScaleValues
    
            Do Until intGridRow = gridExportOptions.RowCount
    
                If gridExportOptions.GetRowCellValue(intGridRow, gridExportOptions.Columns(2)) = True Then
                    objAssignment = Nothing
                    intTASK_ID = ReturnTaskID(gridExportOptions.GetRowCellValue(intGridRow, gridExportOptions.Columns(0)))
    
                    If intTASK_ID <> 0 Then
                        objAssignment = appProj.Application.ActiveProject.Tasks(intTASK_ID).Assignments.Add(ResourceID:=appProj.ActiveProject.Resources(strRES_ID).ID) 
                      
                        intCounter = 0
                        Do Until intCounter = dsExportDetail.Tables(0).Rows.Count 'Loop through and insert TimeScaledData
    
                            If dsExportDetail.Tables(0).Rows(intCounter).Item("BD_TASK_ID") = gridExportOptions.GetRowCellValue(intGridRow, gridExportOptions.Columns("MSPTask_UID")) Then
    
                              
                                If CDec(dsExportDetail.Tables(0).Rows(intCounter).Item("Total")) > 60000000 Then
                                    boolWarning = True
                                Else
    
                                    If dsExportDetail.Tables(0).Rows(intCounter).Item(2) Is DBNull.Value Then
    
                                        dateAssign = Now() 'If there is no date, assign data to the current day
    
                                        tsvs = objAssignment.TimeScaleData(dateAssign, dateAssign, 28, 4)
                                        tsvs.Add(dsExportDetail.Tables(0).Rows(intCounter).Item("Total"), 1)
    
                                    Else
    
                                        dateAssign = dsExportDetail.Tables(0).Rows(intCounter).Item(2)
                                        tsvs = objAssignment.TimeScaleData(dateAssign, dateAssign, 28, 4)
    
                                        ' tsvs.Add(dsExportDetail.Tables(0).Rows(intCounter).Item("Total"), 1)
                                        'For Each tsv In tsvs
                                        tsvs(1).Value = dsExportDetail.Tables(0).Rows(intCounter).Item("Total")
                                        ' Next
                                        'Add TSV data
    
                                    End If
                                End If
                            Else
    
                          End If
                            intCounter += 1
                        Loop
         
                    End If
                End If
               intGridRow += 1
    
            Loop

    This code has a couple of issues:

    1)  The Cost total for the task is accurate.  However, the timephased data is still blank.
    2)  The last record for the first task throws an error: "The argument value is not valid."  I don't understand why this is occurring - the date is valid ('6/16/2011'), and the amount is $240.00.

    Any ideas on what I'm missing?

    Thanks!

    Tuesday, July 17, 2012 8:32 PM

All replies

  • You've asked this before? I think I answered, no need to use tsvs.add as a time slice is automatically added my Timescaledata for each date in the date range. I also said get it working in VBA first, then all you have to worry about is converting to VSTO, which is often a hit and miss afair. At least if it works in VBA you only have to worry about Visual Studio and VSTO!

    Rod Gill

    The one and only Project VBA Book

    Rod Gill Project Management

    Thursday, July 19, 2012 5:27 AM
    Moderator
  • Actually, I did change how it worked - I removed the tsvs.add section.  You'll notice it's commented out.

    The code that's throwing the error now looks like this:

    dateAssign = dsExportDetail.Tables(0).Rows(intCounter).Item(2)
    tsvs = objAssignment.TimeScaleData(dateAssign, dateAssign, 28, 4)
    tsvs(1).Value = dsExportDetail.Tables(0).Rows(intCounter).Item("Total")

    I'll try moving it over to VBA and playing with it there, but I wanted to throw it out there and see if I'd made any obvious mistakes.
    Thursday, July 19, 2012 9:01 PM
  • Its not commented out in the first part of the IF statement. You need to clear the Actual Costs are always calculated by Project option under File, Options, Schedule (Project 2010).

    The following VBA code works for me:

    Sub Test() Dim Tsk As Task Dim tsvs As TimeScaleValues Set Tsk = ActiveProject.Tasks(1) Set tsvs = Tsk.Assignments(1).TimeScaleData(Tsk.Start, Tsk.Finish, _
    pjAssignmentTimescaledActualCost, pjTimescaleDays, 1) tsvs(1).Value = 10000 End Sub



    Rod Gill

    The one and only Project VBA Book

    Rod Gill Project Management

    Friday, July 20, 2012 3:38 AM
    Moderator
  • Alright, I've narrowed down the issue.

    I'm using the code you suggested, which works perfectly, except for the issue listed above.  No matter what I do, how I change the data, Microsoft Project finds a line where it decides to blank out all the values in the timephased data.  I can watch it happen as I step through the code - a value assigns, another value assigns, and then suddenly one of the assignments makes all the timephased data for the resource disappear.    Of course, when all the timephased fields are blanked out, you can't put data in them.  This means that the next time my program tries to assign actual cost data, Microsoft Project throws an error: "The argument value is not valid." , referring to the timescaledata location (which no longer exists).

    Here's  the thing:

    This only happens with Microsoft Project 2003.  I downloaded a trial of Microsoft Project 2010, and it ran PERFECTLY.  In other words, this is a bug in Microsoft's code.

    SO, my question is not what's wrong with MY code, but what issues everyone is aware of with MICROSOFT'S code that I may need to work around.  Does anyone know why Project 2003 is causing this problem, and if so, how to work around it?

    Thanks!

    Dusitin

    Wednesday, August 8, 2012 6:41 PM
  • Are you on Project 2003 SP3? If not, try updating. If you are, then does it work in VBA? Getting the macro working in VBA before converting to VSTO probably halves the development time. For example in your case we would know if it's a Proejct 2003 problem, a VBA problem or a VSTO problem.

    I think your quickest way to finding an answer is to get the code working in VBA first. If it does work, then there's a VSTO problem and I supect teh fix is called Proejct 2007 or 2020!


    Rod Gill

    The one and only Project VBA Book

    Rod Gill Project Management

    Tuesday, August 14, 2012 1:32 AM
    Moderator