Help me clean this up: making a series of calculation dependent calculations update when changing one of the controls.
I am trying to make a "table" that projects profit depending on number of units sold per month. The trouble that I am having is that if I want to change the number of units sold in Month 6 then I am not getting an automatic update from Month 7 through Month 12.
I have tried this two ways.
1. I have tried putting code in "Form_Current"
2. I have tried putting code in "AfterUpdate" for each month
The problem that I am getting is that in case 1, I have to hit the "Refresh All" button to get the rest of the controls to update; with case 2, I have to go through all of the controls for each subsequent month and reenter the number there.
Case 1 Code
Code:
Private Sub Form_Current()
Me.ProfPerM1 = Me.UnitsPerM1 * Me.ProfPerUnit
Me.ProfPerM2 = Me.UnitsPerM2 * Me.ProfPerUnit
Me.ProfPerM3 = Me.UnitsPerM3 * Me.ProfPerUnit
Me.ProfPerM4 = Me.UnitsPerM4 * Me.ProfPerUnit
Me.ProfPerM5 = Me.UnitsPerM5 * Me.ProfPerUnit
Me.ProfPerM6 = Me.UnitsPerM6 * Me.ProfPerUnit
Me.ProfPerM7 = Me.UnitsPerM7 * Me.ProfPerUnit
Me.ProfPerM8 = Me.UnitsPerM8 * Me.ProfPerUnit
Me.ProfPerM9 = Me.UnitsPerM9 * Me.ProfPerUnit
Me.ProfPerM10 = Me.UnitsPerM10 * Me.ProfPerUnit
Me.ProfPerM11 = Me.UnitsPerM11 * Me.ProfPerUnit
Me.ProfPerM12 = Me.UnitsPerM12 * Me.ProfPerUnit
Me.SumM1 = Me.ProfPerM1
Me.SumM2 = Me.SumM1 + Me.ProfPerM2
Me.SumM3 = Me.SumM2 + Me.ProfPerM3
Me.SumM4 = Me.SumM3 + Me.ProfPerM4
Me.SumM5 = Me.SumM4 + Me.ProfPerM5
Me.SumM6 = Me.SumM5 + Me.ProfPerM6
Me.SumM7 = Me.SumM6 + Me.ProfPerM7
Me.SumM8 = Me.SumM7 + Me.ProfPerM8
Me.SumM9 = Me.SumM8 + Me.ProfPerM9
Me.SumM10 = Me.SumM9 + Me.ProfPerM10
Me.SumM11 = Me.SumM10 + Me.ProfPerM11
Me.SumM12 = Me.SumM11 + Me.ProfPerM12
End Sub
Case 2 Code
Code:
Private Sub UnitsPerM1_AfterUpdate()
Me.ProfPerM1 = Me.UnitsPerM1 * Me.ProfPerUnit
Me.SumM1 = Me.ProfPerM1
End Sub
Private Sub UnitsPerM2_AfterUpdate()
Me.ProfPerM2 = Me.UnitsPerM2 * Me.ProfPerUnit
Me.SumM2 = Me.SumM1 + Me.ProfPerM2
End Sub
........ etc
Private Sub UnitsPerM12_AfterUpdate()
Me.ProfPerM12 = Me.UnitsPerM12 * Me.ProfPerUnit
Me.SumM12 = Me.SumM11 + Me.ProfPerM12
End Sub
The one solution that I have thought of that would yield the result that I desire would be to implement Case 1 in all of the "After_Update" events for months 1 through 12. This solution just feels sloppy to me. I was wondering if there is a cleaner way to do this?