ACC95: Missing Variable Declarations in Rate Function Example

Last reviewed: August 29, 1997
Article ID: Q160504
The information in this article applies to:
  • Microsoft Access 7.0

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

  1. Open the sample database Northwind.mdb.

  2. Create a module and type the following line in the Declarations section:

          Option Explicit
    

  3. Type the following procedure:

          Function TryRate()
    

          End Function
    

  4. Search the Help Index for Rate function and open the topic.

  5. Click the Example link at the top of the Rate Function Help topic.

  6. Select the sample code, and then press CTRL+C to copy the contents to the Clipboard.

  7. Close the Rate Function Example and Rate Function Help windows.

  8. 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
    
    

  9. On the Run menu, click Compile Loaded Modules. Note that you receive the error message:

          Variable not defined
    
Keywords          : DcmHlp kberrmsg PgmDecl SynFnc
Version           : 7.0
Platform          : WINDOWS
Hardware          : x86
Issue type        : kbdocerr


================================================================================


THE INFORMATION PROVIDED IN THE MICROSOFT KNOWLEDGE BASE IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND. MICROSOFT DISCLAIMS ALL WARRANTIES, EITHER EXPRESS OR IMPLIED, INCLUDING THE WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL MICROSOFT CORPORATION OR ITS SUPPLIERS BE LIABLE FOR ANY DAMAGES WHATSOEVER INCLUDING DIRECT, INDIRECT, INCIDENTAL, CONSEQUENTIAL, LOSS OF BUSINESS PROFITS OR SPECIAL DAMAGES, EVEN IF MICROSOFT CORPORATION OR ITS SUPPLIERS HAVE BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. SOME STATES DO NOT ALLOW THE EXCLUSION OR LIMITATION OF LIABILITY FOR CONSEQUENTIAL OR INCIDENTAL DAMAGES SO THE FOREGOING LIMITATION MAY NOT APPLY.

Last reviewed: August 29, 1997
© 1998 Microsoft Corporation. All rights reserved. Terms of Use.