I was a Philosophy major, too. Think sentential calculus!
Here is what I would do:
Create a table with these columns:
tblTarget
Product - text
Amount - currency
BillingDate - date
Then create a DELETE query to clean out this table:
qryDELETE_Target
DELETE FROM tblTarget
Then create a form to run your report from that has two combo boxes:
cboMonth
Column 0
1
2
3
...
Column 1
Jan
Feb
Mar
...
cboYear
Column 0
2008
2009
2010
...
Then have the user select a Month and Year before running the report. Then, assuming you have the report built and ready to accept data, do this:
Dim rs_Source As ADODB.Recordset
Dim rs_Target As ADODB.Recordset
Dim sSQL_S As String
Dim sSQL_T As String
Dim sProduct As String
Dim iTerm As Integer
Dim lAmount As Long
Dim dtBDate As Date
Dim dtRDate As Date
Dim iMonth As Integer
Dim iYear As Integer
Dim i As Integer
iMonth = Me.cboMonth
iYear = Me.cboYear
sSQL_S = "SELECT * FROM tblMySourceTable"
sSQL_T = "SELECT * FROM tblTarget"
Set rs_Source = New ADODB.Recordset
rs_Source.Open sSQL_S, CurrentProject.Connection, adOpenDynamic, adLockOptimistic
Set rs_Target = New ADODB.Recordset
rs_Target.Open sSQL_T, CurrentProject.Connection, adOpenDynamic, adLockOptimistic
rs_Source.MoveFirst
Do Until rs_Source.EOF
sProduct = rs_Source("Product")
iTerm = rs_Source("BillingTerm")
lAmount = rs_Source("BillingAmount")
dtBDate = rs_Source("BillingDate")
dtRDate = dtBDate
lRecAmnt = lAmount / iTerm
i = 1
Do Until i = iTerm + 1
If DatePart("m", dtRDate) = iMonth AND DatePart("yyyy", dtRDate) = iYear Then
rs_Target.AddNew
rs_Target("Product") = sProduct
rs_Target("Amount") = lRecAmnt
rs_Target("BillingDate") = dtRDate
rs_Target.Update
End If
dtRDate = DateAdd("m", i, dtBDate)
i = i + 1
Loop
rs_Source.MoveNext
Loop
DoCmd.OpenReport "rptYourReportName", acPreview...
Okay, this has not been tested. Please use a copy of the database to test this.
Does it work for you? It will take a long time to process because of the nested loops, but it will be accurate. You may want to export the resulting table to Excel instead of running a report that you will have to PDF to save.
mmcdonal
Look it up at:
http://wrox.books24x7.com