Microsoft KB Archive/98796

= ACC: Data Type of Value Overrides Data Type of Variable =

Article ID: 98796

Article Last Modified on 1/18/2007

-

APPLIES TO


 * Microsoft Access 1.0 Standard Edition
 * Microsoft Access 1.1 Standard Edition
 * Microsoft Access 2.0 Standard Edition
 * Microsoft Access 95 Standard Edition
 * Microsoft Access 97 Standard Edition

-



This article was previously published under Q98796



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



SUMMARY
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:

 Open a new module.  Add the following line underneath the Option Compare Database line: Dim v as Currency  Press ENTER. On the View menu, click Debug window (or Immediate Window in versions 1.x and 2.0). In the Debug window, type the following line, and then press ENTER:

v=123456789123.3456789#

 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.</li> Repeat steps 5-6, replacing # with other type-declaration characters</li></ol>

(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 &quot;invalid number&quot; error message is displayed.

Additional query words: ui misc

Keywords: kbinfo kbprogramming KB98796

-

[mailto:TECHNET@MICROSOFT.COM Send feedback to Microsoft]

© Microsoft Corporation. All rights reserved.