There's no way to do this in plain Access' SQL dialect. So, VBA is the choice.
You will need to create a table to hold the values. Let's say your output table is something like this:
Table: tbl_output
FY Integer
Calculated Double
The VBA code:
public sub fillCalculatedValues()
Dim db as DAO.Database, rsIn as DAO.RecordSet, rsOut as DAO.RecordSet
Dim strSQL as String
Dim value as Double, fy as Integer, i as Integer
' Connect to the current database
Set db = currentDb()
' Get the values from your input table (let's say it is called tbl_in) in read only mode
strSQL = "SELECT * FROM tbl_in ORDER BY FY"
rsIn = db.OpenRecordSet(strSQL, dbOpenDynaset, dbReadOnly)
' Initialize your output table
strSQL = "DELETE FROM tbl_output"
DoCmd.RunSQL strSQL
' Open the output table (allowing edits)
rsOut = db.OpenRecordset("tbl_output", dbOpenDynaset, dbEditAdd)
' Read the input row by row, and insert a new row in the output
with rsIn
.moveFirst
i = 1
value = 1
do
fy = ![FY] ' Read the field FY from rsIn
' Insert the new row in the output table
rsOut.addNew
rsOut![FY] = fy
rsOut![calculated] = value
rsOut.update
' Update the calculated value
value = value * ![percent]
' Advance one row
.moveNext
loop until .EOF ' Loop until you get to the end of the table
end with
' Close everything
rsOut.close
rsIn.close
db.close
end sub
This is just an example. You should modify it to fit your specific needs
Hope this helps.
P.S.:
- A little easter egg for you: The Ten Commandments of Access
- If you are willing to move up from Access to a more robust RDBMS, I suggest you take your chances with MySQL. There are some tricks you can use in MySQL to do this sort of things. You can take a look to this post to know how to make a cummulative sum over a set of rows in MySQL, and fit it to your needs (after all, you are making a cummulative product)