Wrox Programmer Forums
|
Access Discussion of Microsoft Access database design and programming. See also the forums for Access ASP and Access VBA.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Access section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old September 5th, 2007, 07:53 PM
Registered User
 
Join Date: Sep 2007
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default IRR function or array

I'm trying to use the IRR function in Access to calculate across roughly 5 years of quarterly cash flows. Currently my data is organized in a single row with columns labled CF1 to CF20. I keep getting "Undefined function 'IRR' in expression" I am not great with Access, I know how to write SQL scripts but never really used Access for anything, but if somebody could tell me how or if it is possible to perform this function I would really appreciate it.

Thanks
 
Old September 7th, 2007, 10:32 AM
Friend of Wrox
 
Join Date: Mar 2004
Posts: 3,069
Thanks: 0
Thanked 10 Times in 10 Posts
Default

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
 
Old September 7th, 2007, 10:34 AM
Friend of Wrox
 
Join Date: Mar 2004
Posts: 3,069
Thanks: 0
Thanked 10 Times in 10 Posts
Default

Sorry, the query would have CashFlow from the CashFlow table, not CF1 - CF20. If the numbers are not available like that, then create a temp table and post the values to the temp table and work in the proper format from there.

mmcdonal
 
Old September 7th, 2007, 10:37 AM
Friend of Wrox
 
Join Date: Mar 2004
Posts: 3,069
Thanks: 0
Thanked 10 Times in 10 Posts
Default

Also, if you were using the proper table structure, then you would take the record count from the query as a Count() column first (iCount variable as Integer), then pull the data into a recordset, then do this:

Do Until i = iCount + 1
   IRRArray(i) = rs("CashFlow")
   i = i + 1
   rs.MoveNext
Loop


mmcdonal





Similar Threads
Thread Thread Starter Forum Replies Last Post
Function returning an array rfstuck Pro VB 6 5 March 12th, 2008 07:35 AM
Passing an array to a Sub or Function donrafeal Access VBA 2 May 11th, 2006 09:39 AM
Function to Clear Text array! ebycorreia_81 VB How-To 1 January 16th, 2006 05:47 AM
Question on the ARRAY function savoym VBScript 6 May 31st, 2005 06:53 AM
How to return array value from a function nebpro BOOK: Beginning PHP4/PHP 5 ISBN: 978-0-7645-4364-7; v5 ISBN: 978-0-7645-5783-5 1 September 29th, 2004 12:14 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.