ACC: Data Type of Value Overrides Data Type of Variable

Last reviewed: August 29, 1997
Article ID: Q98796
The information in this article applies to:
  • Microsoft Access versions 1.0, 1.1, 2.0, 7.0, 97

SUMMARY

Moderate: Requires basic macro, coding, and interoperability skills.

Microsoft Access internally converts values with implicit data type definitions before assigning those values to variables. This may result in unexpected rounding of numbers, or in the following error message:

   Invalid Number

MORE INFORMATION

You can implicitly define the data type of a value by appending a type-declaration character at the end of the value. For example, x=1234& implicitly defines 1234 as a Long data type (four-byte integer).

To see how this works, follow these steps:

  1. Open a new module.

  2. Add the following line underneath the Option Compare Database line:

          Dim v as Currency
    

  3. Press ENTER.

  4. On the View menu, click Debug window (or Immediate Window in versions 1.x and 2.0).

  5. In the Debug window, type the following line, and then press ENTER:

          v=123456789123.3456789#
    

  6. Type the following line, and then press ENTER again.

          debug.print v
    

    Note that the value of the variable <v> is now 123456789123.3457. The number sign (#) implicitly defined the value as a double-precision value. Microsoft Access internally converted the value to that data type before assigning it to the currency variable.

  7. Repeat steps 5-6, replacing # with other type-declaration characters (such as the ampersand (&), exclamation point (!), or At sign (@)).

    The At sign defines the currency data type, which is limited to four decimal places. When you try to define a number with more than four decimal places as currency, an "invalid number" error message is displayed.


Additional query words: ui misc
Keywords : kbprg PgmDecl PgmOthr SynGnrl
Version : 1.0 1.1 2.0 7.0 97
Platform : WINDOWS
Hardware : x86
Issue type : kbinfo


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.