Microsoft KB Archive/125773

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

Article ID: 125773

Article Last Modified on 1/19/2007

-

APPLIES TO


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

-



This article was previously published under Q125773





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

This article shows you 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:

  Create a new module and enter the following line in the Declarations section if it is not already there: Option Explicit   Type or paste the following procedure.

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  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). 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, there is a space in Employee ID field name.

Note that the description for the EmployeeID field is returned.

