IRR is available in VBA. How are you using it now that you are getting an error? Are you trying to use it in a query? If so, it won't work (I don't think.)
First of all, you need to have a Cash Flow table, not a table with 20 cash flow columns. That is not n programming. You are limited to 20 values and then you are done. Do this:
tblProject
ProjectID
ProjectName
etc
tblCashFlow
CashFlowID
ProjectID - FK
Quarter_Year(?)
CashFlow
This way your queries will work muuuuuuuch better, and you can runa project for more than 5 years - if you are working in quarters.
You will need to post the values from your table to an array (one payment and x cash returns - so must have one negative number). The array must have Doubles).
So for example, create a report with the fields CF1 - CF20 (assuming CF1 is your initial investment - if not, supply that). The fields can be Visible = No. Alternatively, have the values waiting in a query, and then package them from the query.
Then on the Detail section's On Format event, take those values into an array, then in an unbound text box, output the function.
So (I will assume you are using a ProjectID for each IRR):
Dim IRRArray As Variant
Dim rs As ADODB.Recordset
Dim sSQL As String
Dim iProj As Integer
Dim i As Integer
Dim dIRR As Double
iProj = Me.ProjectID
i = 0
ReDim IRRArray(20)
sSQL = "SELECT * FROM qryMyCashFlow WHERE [ProjectID] = " & iProj
Set rs = New ADODB.Recordset
rs.Open sSQL, CurrentProject.Connection, adOpenDynamic, adLockOptimistic
rs.MoveFirst
Do Until i = 20
IRRArray(i) = rs("CashFlow")
i = i + 1
rs.MoveNext
Loop
dIRR = Irr(IRRArray)
Me.UnBoundTextBox = dIRR
I think that should work.
mmcdonal
|