INF: Sample Function to Return Variable's Data Type Name

    Article ID: Q109945
    Creation Date: 10-JAN-1994
    Revision Date: 19-SEP-1996

    The information in this article applies to:

    • Microsoft Access versions 1.0, 1.1, 2.0

    SUMMARY

    Advanced: Requires expert coding, interoperability, and multiuser skills.

    The built-in VarType() function returns a value that indicates a variable's data type. This article describes a sample Access Basic function you can use to return the data type's name.

    This article assumes that you are familiar with Access Basic and with creating Microsoft Access applications using the programming tools provided with Microsoft Access. For more information on Access Basic, please refer to the "Introduction to Programming" manual in Microsoft Access version 1.x, or the "Building Applications" manual, Chapter 3, "Introducing Access Basic," in version 2.0.

    MORE INFORMATION

    To create the sample function DataTypeName(), type the following code in a new or existing module:

    NOTE: In the following sample code, an underscore (_) is used as a line- continuation character. Remove the underscore from the end of the line when re-creating this code in Access Basic.

       '******************************************************
       'Declarations Section of Module
       '******************************************************
       Option Explicit
    
       '======================================================
       ' Purpose: To return the data type name.
       ' Accepts: A data type value.
       '======================================================
       Function DataTypeName (MyValue)
          DataTypeName = Choose(VarType(MyValue) + 1, "Empty", _
             "Null", "Integer", "Long", "Single", "Double", _
             "Currency", "Date", "String")
       End Function
    
    
    To try the DataTypeName() function, type the following line in the module's Immediate window, and then press ENTER:

       ? DataTypeName(2)
    
    
    REFERENCES

    Microsoft Access "Language Reference," version 1.0, "Choose Function," page 65, and "VarType Function," page 494


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.
©1997 Microsoft Corporation. All rights reserved. Legal Notices.

Additional reference words: 1.00 1.10 2.00 function datatype vartype
KBCategory: kbusage
KBSubcategory: ExrOthr