dominicg123
Technical User
I am trying to do a report with an amortization table. This is a function that comes from Microsoft website that shows the payment for each period with different details. There is a counter that shows each period of payment. I trying to show a date for each period that change on each line but it doesn’t work. This is my code:
Option Compare Database
Option Explicit
'When payments can be made.
Const ENDPERIOD = 0
Const BEGINPERIOD = 1
'Define variables.
Dim intTotPmts As Integer
Dim intPeriod As Integer
Dim curMonthlyPmt As Currency
Dim curInterest As Currency
Dim dblRate As Double
Dim dblPresentVal As Double
Dim dblPrincipalPmt As Double
Dim varFutureVal As Variant
Dim varPmtMade As Variant
Dim DtPretDateNext As Date
Private Sub EntêteÉtat_Format(Cancel As Integer, FormatCount As Integer)
'Initialize the variables.
intPeriod = 1
varFutureVal = 0
dblPresentVal = Forms!Prets!PretAMT
dblRate = Forms!Prets!PretTaux
Select Case Forms!Prets!PretFrequence
Case 7
intTotPmts = 52
Case 14
intTotPmts = 26
Case 30
intTotPmts = 12
End Select
'Ensure APR is in decimal format.
If dblRate > 1 Then
dblRate = dblRate / 100
End If
varPmtMade = ENDPERIOD
'Calculate monthly payment.
Me!txtMonthlyPmt = Abs(-Pmt(dblRate / intTotPmts, intTotPmts, dblPresentVal, _
varFutureVal, varPmtMade))
End Sub
Private Sub Détail_Format(Cancel As Integer, FormatCount As Integer)
'Calculate and round the amount of payment that goes toward Principal.
dblPrincipalPmt = PPmt(dblRate / intTotPmts, intPeriod, _
intTotPmts, -dblPresentVal, varFutureVal, varPmtMade)
dblPrincipalPmt = (Int((dblPrincipalPmt + 0.005) * 100) / 100)
'Calculate and round the amount of payment that goes toward Interest.
curInterest = Me!txtMonthlyPmt - dblPrincipalPmt
curInterest = (Int((curInterest + 0.005) * 100) / 100)
Select Case Forms!Prets!PretFrequence
Case 7
DtPretDateNext = DateAdd("d", 7, Forms!Prets!PretDateDebut)
Case 14
DtPretDateNext = DateAdd("d", 14, Forms!Prets!PretDateDebut)
Case 30
DtPretDateNext = DateAdd("m", 1, Forms!Prets!PretDateDebut)
End Select
'Print the payments, principal, and interest.
Me!txtMonth = intPeriod
Me!txtPayment = Me!txtMonthlyPmt
Me!txtPrincipalPmt = dblPrincipalPmt
Me!txtInterest = curInterest
Me!txtdate = DtPretDateNext
End Sub
Private Sub Détail_Print(Cancel As Integer, PrintCount As Integer)
'Continue calculating until counter equals number of payments.
intPeriod = intPeriod + 1
DtPretDateNext = DateAdd("d", 7, DtPretDateNext)
'Calculate payments and interest for each payment period.
If intPeriod <= intTotPmts Then
Me.NextRecord = False
End If
End Sub
Option Compare Database
Option Explicit
'When payments can be made.
Const ENDPERIOD = 0
Const BEGINPERIOD = 1
'Define variables.
Dim intTotPmts As Integer
Dim intPeriod As Integer
Dim curMonthlyPmt As Currency
Dim curInterest As Currency
Dim dblRate As Double
Dim dblPresentVal As Double
Dim dblPrincipalPmt As Double
Dim varFutureVal As Variant
Dim varPmtMade As Variant
Dim DtPretDateNext As Date
Private Sub EntêteÉtat_Format(Cancel As Integer, FormatCount As Integer)
'Initialize the variables.
intPeriod = 1
varFutureVal = 0
dblPresentVal = Forms!Prets!PretAMT
dblRate = Forms!Prets!PretTaux
Select Case Forms!Prets!PretFrequence
Case 7
intTotPmts = 52
Case 14
intTotPmts = 26
Case 30
intTotPmts = 12
End Select
'Ensure APR is in decimal format.
If dblRate > 1 Then
dblRate = dblRate / 100
End If
varPmtMade = ENDPERIOD
'Calculate monthly payment.
Me!txtMonthlyPmt = Abs(-Pmt(dblRate / intTotPmts, intTotPmts, dblPresentVal, _
varFutureVal, varPmtMade))
End Sub
Private Sub Détail_Format(Cancel As Integer, FormatCount As Integer)
'Calculate and round the amount of payment that goes toward Principal.
dblPrincipalPmt = PPmt(dblRate / intTotPmts, intPeriod, _
intTotPmts, -dblPresentVal, varFutureVal, varPmtMade)
dblPrincipalPmt = (Int((dblPrincipalPmt + 0.005) * 100) / 100)
'Calculate and round the amount of payment that goes toward Interest.
curInterest = Me!txtMonthlyPmt - dblPrincipalPmt
curInterest = (Int((curInterest + 0.005) * 100) / 100)
Select Case Forms!Prets!PretFrequence
Case 7
DtPretDateNext = DateAdd("d", 7, Forms!Prets!PretDateDebut)
Case 14
DtPretDateNext = DateAdd("d", 14, Forms!Prets!PretDateDebut)
Case 30
DtPretDateNext = DateAdd("m", 1, Forms!Prets!PretDateDebut)
End Select
'Print the payments, principal, and interest.
Me!txtMonth = intPeriod
Me!txtPayment = Me!txtMonthlyPmt
Me!txtPrincipalPmt = dblPrincipalPmt
Me!txtInterest = curInterest
Me!txtdate = DtPretDateNext
End Sub
Private Sub Détail_Print(Cancel As Integer, PrintCount As Integer)
'Continue calculating until counter equals number of payments.
intPeriod = intPeriod + 1
DtPretDateNext = DateAdd("d", 7, DtPretDateNext)
'Calculate payments and interest for each payment period.
If intPeriod <= intTotPmts Then
Me.NextRecord = False
End If
End Sub