Share via


Task.ActualCost Property

Project Developer Reference

Returns the actual cost for an assignment, resource, or task. Read-only Variant.

Syntax

expression.ActualCost

expression   A variable that represents a Task object.

Return Value
Variant

Remarks

The ActualCost property can be set for Assignment and Task objects (but not summary tasks) if the Actual costs are always calculated by Microsoft Office Project check box has been cleared on the Calculation tab of the Options dialog box.

Example

The following example prompts the user for actual costs of tasks with no resources in the active project. It assumes that the Actual costs are always calculated by Microsoft Office Project check box has been cleared.

Visual Basic for Applications
  Sub GetActualCostsForTasks()
Dim Entry As String     ' User input
Dim T As Task           ' Task object used in For Each loop

' Count the resources of each task in the active project.
For Each T In ActiveProject.Tasks

    ' If a task has no resources, then prompt user for actual cost.
    If T.Resources.Count = 0 Then
    
        Do While 1
            Entry = InputBox$("Enter the cost for " & T.Name & ":")

            ' Exit loop if user enters number or clicks Cancel.
            If IsNumeric(Entry) Or Entry = Empty Then
                Exit Do

            ' User didn't enter a number; tell user to try again.
            Else
                MsgBox ("You didn't enter a number; try again.")
            End If
        Loop

        ' If user didn't click Cancel, assign actual cost to task.
        If Not StrComp(Entry, Empty, 1) = 0 Then T.<strong class="bterm">ActualCost</strong> = Entry
    End If
        
Next T

End Sub

See Also