ID: Q125773
The information in this article applies to:
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.
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 Declarations
section if it is not already there:
Option Explicit
2. 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
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, there is a space in Employee ID field
name.
Note that the description for the EmployeeID field is returned.
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 MdlDao PgmObj
Version : 2.0 7.0 97
Platform : WINDOWS
Hardware : x86
Issue type : kbhowto
Last Reviewed: November 21, 1998