ACC: How to Use DAO to Retrieve a Field's Description

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

SUMMARY

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

This article describes how to use data access objects (DAO) to retrieve the description stored with a field in a table definition.

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 your version of the "Building Applications with Microsoft Access" manual.

NOTE: Visual Basic for Applications is called Access Basic in Microsoft Access version 2.0. For more information about Access Basic, please refer to the "Building Applications" manual.

MORE INFORMATION

Each field has a Description property that you can reference with DAO. The following example demonstrates how to return a field's description:

  1. Create a new module and enter the following line in the module's Declarations section if it is not already there:

          Option Explicit
    

  2. Create the following procedure in the module.

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

          Function GetFieldDescription (ByVal MyTableName As String, _
          ByVal MyFieldName As String)
    
             Dim DB As Database
             Dim TD As TableDef
             Dim FLD As Field
    
             Set DB = DBEngine.Workspaces(0).Databases(0)
    
             On Error GoTo Err_GetFieldDescription
    
             Set TD = DB.TableDefs(MyTableName)
             Set FLD = TD.Fields(MyFieldName)
    
             GetFieldDescription = FLD.Properties("Description")
    
          Bye_GetFieldDescription:
             Exit Function
    
          Err_GetFieldDescription:
             Beep: MsgBox Error$, 48
             GetFieldDescription = Null
             Resume Bye_GetFieldDescription
    
          End Function
    
    

  3. To test this function in the sample database Northwind.mdb (or NWIND.MDB in version 2.0), click Debug Window on the View menu (or Immediate Window in version 2.0).

  4. In the Debug Window (or Immediate window in version 2.0), type the following line, and then press ENTER:

          ? GetFieldDescription("Employees", "EmployeeID")
    

    NOTE: In Microsoft Access 2.0, type a space in "Employee ID".

    Note that the description for the EmployeeID field is returned.

REFERENCES

For more information about the TableDefs collection, search the Help Index for "TableDefs" and then "TableDefs Collection," or ask the Microsoft Access 97 Office Assistant.

For more information about the Properties collection, search the Help Index for "Properties, Collections" or "Property," and then "Property Object, Properties Collection" or ask the Microsoft Access 97 Office Assistant.


Additional query words: programming
Keywords : kbprg PgmHowTo PgmObj MdlDao
Version : 2.0 7.0 97
Platform : WINDOWS
Hardware : x86
Issue type : kbhowto


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.