Hi,
I need to add in a function to a database that calculates IRR for each of many reference numbers, everything is in flat file at the moment but I can get around that to list cashflows in rows for each ref if I have to. I found a thread where someone wrote some VB to do this for a set or refs which all had 4 cashflows, but my data has varying amounts, some with overs 40 cashflows.
I need to write a piece of code like the one in this thread but which just uses all of the cashflows listed no matter how many, rather than a rigid formula using 4 cashflows.
It would be even better if I could keep the data in flat file format and have some code that creates a temporary query with the cashflows in a column for each ref and then iterates through all of the ref numbers?
Does anyone have any ideas?
This is the code that someone wrote in the other thread and I have attached the example database:
Public Sub pop()
Dim Guess, Fmt, RetRate, Msg
Static Values(5) As Double
Dim db As Database
Dim rec As Recordset
Set db = CurrentDb()
Set rec = db.OpenRecordset("Test Data")
Do Until rec.EOF
Guess = 0.1
Values(0) = rec.Fields("M00")
Values(1) = rec.Fields("M01"): Values(2) = rec.Fields("M02")
Values(3) = rec.Fields("M03")
RetRate = IRR(Values(), Guess)
rec.Edit
rec.Fields("IRR") = RetRate
rec.Update
rec.MoveNext
Loop
rec.Close
Set db = Nothing
Set rec = Nothing
End Sub
I need to add in a function to a database that calculates IRR for each of many reference numbers, everything is in flat file at the moment but I can get around that to list cashflows in rows for each ref if I have to. I found a thread where someone wrote some VB to do this for a set or refs which all had 4 cashflows, but my data has varying amounts, some with overs 40 cashflows.
I need to write a piece of code like the one in this thread but which just uses all of the cashflows listed no matter how many, rather than a rigid formula using 4 cashflows.
It would be even better if I could keep the data in flat file format and have some code that creates a temporary query with the cashflows in a column for each ref and then iterates through all of the ref numbers?
Does anyone have any ideas?
This is the code that someone wrote in the other thread and I have attached the example database:
Public Sub pop()
Dim Guess, Fmt, RetRate, Msg
Static Values(5) As Double
Dim db As Database
Dim rec As Recordset
Set db = CurrentDb()
Set rec = db.OpenRecordset("Test Data")
Do Until rec.EOF
Guess = 0.1
Values(0) = rec.Fields("M00")
Values(1) = rec.Fields("M01"): Values(2) = rec.Fields("M02")
Values(3) = rec.Fields("M03")
RetRate = IRR(Values(), Guess)
rec.Edit
rec.Fields("IRR") = RetRate
rec.Update
rec.MoveNext
Loop
rec.Close
Set db = Nothing
Set rec = Nothing
End Sub