J
JK
Using Access 2003, I’m trying to have a db auto calculate an assets
depreciation values over a user specified time period. I have a main form
“frmAssets†a subform “frmAssetsSF†and then another subform inside the last
subform “Depreciation Subform.â€
Using the template example for recurring events, the subform is populated
but the data is not bound to a table. The only time the data is bound is if
it’s an exception. I like this concept and would like to be able to calculate
the depreciation values and then display them in a subform without having to
store the values in a table.
I found the following MS example online. It’s a great bit of code. It asks
for the initial cost of the asset, salvage value, and the assets useful life
in months. Then, you specify the year you would like to calculate, hit enter,
and the depreciation value is displayed. This is not straight line DP; the
values are different from year to year.
On subform “frmAssetsSF†I have the following fields that can be pointed to:
[PurchaseDate]
[PurchasePrice]
[SalvageValue]
[DepreciableLife] – months
If the purchase date is: 12/15/2008
And the purchase price is: $5,000
And the salvage value is: $100
And the depreciable life is: 60 months (5 years)
The following should be displayed in the subform:
Date: Depreciation Amount:
12/15/2009 $2,000.00
12/15/2009 $1,200.00
12/15/2010 $720.00
12/15/2011 $432.00
12/15/2012 $259.20
I know this is a lot to ask. But if someone could point me in the right
direction I would greatly appreciate it.
Private Sub cmdDepreciation_Click()
Dim lngErr As Long, strError As String
Dim Fmt, InitCost, SalvageVal, MonthLife, LifeTime, DepYear, Depr
Const YRMOS = 12 ' Number of months in a year.
On Error GoTo Save_Error
Fmt = "###,##0.00"
InitCost = InputBox("What's the initial cost of the asset?")
SalvageVal = InputBox("Enter the asset's value at end of its life.")
MonthLife = InputBox("What's the asset's useful life in months?")
Do While MonthLife < YRMOS ' Ensure period is >= 1 year.
MsgBox "Asset life must be a year or more."
MonthLife = InputBox("What's the asset's useful life in months?")
Loop
LifeTime = MonthLife / YRMOS ' Convert months to years.
If LifeTime <> Int(MonthLife / YRMOS) Then
LifeTime = Int(LifeTime + 1) ' Round up to nearest year.
End If
DepYear = CInt(InputBox("Enter year for depreciation calculation."))
Do While DepYear < 1 Or DepYear > LifeTime
MsgBox "You must enter at least 1 but not more than " & LifeTime
DepYear = InputBox("Enter year for depreciation calculation.")
Loop
Depr = DDB(InitCost, SalvageVal, LifeTime, DepYear)
MsgBox "The depreciation for year " & DepYear & " is " & _
Format(Depr, Fmt) & "."
End Sub
depreciation values over a user specified time period. I have a main form
“frmAssets†a subform “frmAssetsSF†and then another subform inside the last
subform “Depreciation Subform.â€
Using the template example for recurring events, the subform is populated
but the data is not bound to a table. The only time the data is bound is if
it’s an exception. I like this concept and would like to be able to calculate
the depreciation values and then display them in a subform without having to
store the values in a table.
I found the following MS example online. It’s a great bit of code. It asks
for the initial cost of the asset, salvage value, and the assets useful life
in months. Then, you specify the year you would like to calculate, hit enter,
and the depreciation value is displayed. This is not straight line DP; the
values are different from year to year.
On subform “frmAssetsSF†I have the following fields that can be pointed to:
[PurchaseDate]
[PurchasePrice]
[SalvageValue]
[DepreciableLife] – months
If the purchase date is: 12/15/2008
And the purchase price is: $5,000
And the salvage value is: $100
And the depreciable life is: 60 months (5 years)
The following should be displayed in the subform:
Date: Depreciation Amount:
12/15/2009 $2,000.00
12/15/2009 $1,200.00
12/15/2010 $720.00
12/15/2011 $432.00
12/15/2012 $259.20
I know this is a lot to ask. But if someone could point me in the right
direction I would greatly appreciate it.
Private Sub cmdDepreciation_Click()
Dim lngErr As Long, strError As String
Dim Fmt, InitCost, SalvageVal, MonthLife, LifeTime, DepYear, Depr
Const YRMOS = 12 ' Number of months in a year.
On Error GoTo Save_Error
Fmt = "###,##0.00"
InitCost = InputBox("What's the initial cost of the asset?")
SalvageVal = InputBox("Enter the asset's value at end of its life.")
MonthLife = InputBox("What's the asset's useful life in months?")
Do While MonthLife < YRMOS ' Ensure period is >= 1 year.
MsgBox "Asset life must be a year or more."
MonthLife = InputBox("What's the asset's useful life in months?")
Loop
LifeTime = MonthLife / YRMOS ' Convert months to years.
If LifeTime <> Int(MonthLife / YRMOS) Then
LifeTime = Int(LifeTime + 1) ' Round up to nearest year.
End If
DepYear = CInt(InputBox("Enter year for depreciation calculation."))
Do While DepYear < 1 Or DepYear > LifeTime
MsgBox "You must enter at least 1 but not more than " & LifeTime
DepYear = InputBox("Enter year for depreciation calculation.")
Loop
Depr = DDB(InitCost, SalvageVal, LifeTime, DepYear)
MsgBox "The depreciation for year " & DepYear & " is " & _
Format(Depr, Fmt) & "."
End Sub