ACC95: Missing Variable Declarations in Rate Function Example (160504)
The information in this article applies to:
- Microsoft Access for Windows 95 7.0
This article was previously published under Q160504
Moderate: Requires basic macro, coding, and interoperability skills.
SYMPTOMS
When you use the example procedure in the Rate Function Help topic, you
receive the following error message:
Variable not defined
This article assumes that you are familiar with Visual Basic for
Applications and with creating Microsoft Access applications using the
programming tools provided with Microsoft Access. For more information
about Visual Basic for Applications, please refer to the "Building
Applications with Microsoft Access for Windows 95" manual.
CAUSE
The Rate function example does not dimension a number of the variables it
uses. If you type Option Explicit in the Declarations section of the module
in which you are using the Rate function example, the code does not compile
because all variables have not been declared.
RESOLUTION
Add the following line of code following the Constant declaration in the
example:
Dim Fmt, FVal, Guess, PVal, Payment, TotPmts, PayType, APR
The modified example looks as follows:
Const ENDPERIOD = 0, BEGINPERIOD = 1 ' When payments are made.
Dim Fmt, FVal, Guess, PVal, Payment, TotPmts, PayType, APR
Fmt = "##0.00" ' Define percentage format.
FVal = 0 ' Usually 0 for a loan.
Guess = 0.1 ' Guess of 10 percent.
PVal = InputBox("How much did you borrow?")
Payment = InputBox("What's your monthly payment?")
TotPmts = InputBox("How many monthly payments do you have to make?")
PayType = MsgBox("Do you make payments at the end of the month?", _
vbYesNo)
If PayType = vbNo Then PayType = BEGINPERIOD Else PayType = ENDPERIOD
APR = (Rate(TotPmts, -Payment, PVal, FVal, PayType, Guess) * 12) * 100
MsgBox "Your interest rate is " & Format(CInt(APR), Fmt) & " percent."
Modification Type: | Major | Last Reviewed: | 7/1/2002 |
---|
Keywords: | kberrmsg KB160504 |
---|
|