Practical Learning: Starting the Exercise |
|
- Start Microsoft Access and create a blank database named Compound
Interest
- On the main menu, click Insert -> Forms
- On the New Forms dialog box, make sure Design View is selected and
make sure the combo box is empty:
- Click OK
- Display the Properties window. If you are using MS Access >=
2000, on the Properties window, set the Allow All Design Changes
to Design View Only
- Save the form as CompInterest
- Change its properties as follows:
Caption:
Compound Interest
Record Selectors: No
Navigation Buttons: No
Border Style:
Dialog
- To add the first control, while the form is selected, on the
Toolbox, make sure the Control Wizard button is down .
Click the Group Box control and click somewhere in the form
- In the first page of the wizard, click under Label Names
- Type
Monthly and press the down arrow key. Complete the label names
with Quarterly, Semiannually, and Annually
- Click Next
- Accept to have the default set to Monthly and click Next
- Accept the default values and click Next
- Accept the Option Buttons and click Next
- Set the Caption to Compound Frequency and click Finish
- Change the Name of the new group box control to fraFrequency
-
Design the dialog box and change the properties of the controls as follows:
|
GroupBox: Caption: Preparation |
TextBox |
Label Caption |
TextBox Name |
Format |
Decimal Places |
Default Value |
Principal: |
txtPrincipal |
Currency |
2 |
0 |
Interest Rate: |
txtInterestRate |
Percent |
|
0.0825 |
Periods: |
txtPeriods |
General Number |
0 |
0 |
GroupBox: Caption: Results |
TextBox |
Label Caption |
TextBox Name |
Format |
Decimal Places |
Default Value |
Interest Earned: |
txtInterestEarned |
Currency |
2 |
0 |
Amount Earned: |
txtAmountEarned |
Currency |
2 |
0 |
|
- Implement the Click() event of the Calculate button as follows:
Option Compare Database
Option Explicit
Private Sub cmdCalculate_Click()
Dim Principal As Currency
Dim InterestRate As Double
Dim InterestEarned As Currency
Dim FutureValue As Currency
Dim RatePerPeriod As Double
Dim Periods As Integer
Dim CompoundType As Integer
Dim i As Double
Dim n As Integer
Principal = CCur(txtPrincipal)
InterestRate = CDbl(txtInterestRate)
If fraFrequency.Value = 1 Then
CompoundType = 12
ElseIf fraFrequency.Value = 2 Then
CompoundType = 4
ElseIf fraFrequency.Value = 3 Then
CompoundType = 2
Else
CompoundType = 1
End If
Periods = CInt(txtPeriods)
i = InterestRate / CompoundType
n = CompoundType * Periods
RatePerPeriod = InterestRate / Periods
FutureValue = Principal * ((1 + i) ^ n)
InterestEarned = FutureValue - Principal
txtInterestEarned = CStr(InterestEarned)
txtAmountEarned = CStr(FutureValue)
End Sub
Private Sub cmdClose_Click()
On Error GoTo Err_cmdClose_Click
DoCmd.Close
Exit_cmdClose_Click:
Exit Sub
Err_cmdClose_Click:
MsgBox Err.Description
Resume Exit_cmdClose_Click
End Sub
|
- Test the form
|
|
|