ACC95: Missing Variable Declarations in Rate Function Example
ID: Q160504
|
The information in this article applies to:
SYMPTOMS
Moderate: Requires basic macro, coding, and interoperability skills.
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."
MORE INFORMATION
Steps to Reproduce Behavior
- Open the sample database Northwind.mdb.
- Create a module and type the following line in the Declarations
section:
Option Explicit
- Type the following procedure:
Function TryRate()
End Function
- Search the Help Index for Rate function and open the topic.
- Click the Example link at the top of the Rate Function Help topic.
- Select the sample code, and then press CTRL+C to copy the contents to
the Clipboard.
- Close the Rate Function Example and Rate Function Help windows.
- Place the insertion point in your module under the Function TryRate()
line and press CTRL+V to paste the example. The function now looks as
follows:
Function TryRate()
Const ENDPERIOD = 0, BEGINPERIOD = 1 ' When payments are made.
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."
End Function
- On the Run menu, click Compile Loaded Modules. Note that you receive the
error message:
Variable not defined
Additional query words:
Keywords : kberrmsg
Version : WINDOWS:7.0
Platform : WINDOWS
Issue type :