INFO: Data Access Objects Have Properties Based on Database Type

Last reviewed: December 12, 1997
Article ID: Q129732
The information in this article applies to:
  • Microsoft Visual Basic Professional and Enterprise Editions for Windows, version 5.0
  • Professional and Enterprise Editions of Microsoft Visual Basic, 16-bit and 32-bit, for Windows, version 4.0

SUMMARY

Certain Visual Basic Data Access Objects (DAO), such as the Field, Recordset, and TableDef objects, each have a Properties collection that uniquely characterizes an instance of the object. You can use the default (built-in) properties in the collection or you can create user-defined properties by using the CreateProperty method.

The default properties available in the collection vary depending on the database type. A set of extended properties, referred to as application- defined properties, are available with Microsoft Access databases.

MORE INFORMATION

The built-in properties are available in the Properties collection for all databases including Microsoft Access, Btrieve, dBASE, Microsoft FoxPro, Paradox, and ODBC client-server databases such as SQL Server. For example, the following built-in properties are available in the Properties collection of the TableDef object (using DAO version 3.0):

    Name            SourceTableName
    Updatable       RecordCount
    DateCreated     ValidationRule
    LastUpdated     ValidationText
    Connect         ConflictTable
    Attributes

Additional application-defined properties are available for Microsoft Access databases. For a complete list of built-in and application-defined properties, please see the following topics in the Microsoft Access Help menu:

    Field Object, Fields Collection - Summary
    RecordSet Object, Recordsets Collection - Summary
    TableDef Object, TableDefs Collection - Summary

The application-defined properties will not be a part of the DAO's Properties collection until the values are changed from their default values. You can change an application-defined property default value by using Visual Basic code or by using the Microsoft Access design environment. In Visual Basic code, use the CreateProperty method just as you would to create user-defined properties.

Steps to Display the Properties Collection

  1. Start a new project in Visual Basic. Form1 is created by default.

  2. If using Visual Basic 5.0, establish a reference to DAO 3.5 by clicking References from the Project menu.

  3. Add the following code to the Form1_Click procedure:

          Dim MyDB As Database
          Dim MySet As Recordset
          Dim MyProperty As Property
          Dim MyTableDef as TableDef
    

          ' Access database
          Set MyDB = DBEngine.Workspaces(0).OpenDatabase("biblio.mdb")
          Set MySet = MyDB.OpenRecordset("Authors", dbOpenTable)
          Set MyTableDef = MyDB("Authors")
    

          'display properties collection for Field
          For Each MyProperty In MySet(0).Properties
    
             List1.AddItem MyProperty.Name
          Next
    
          'display properties collection for Recordset
          For Each MyProperty In Myset.Properties
             List2.AddItem MyProperty.Name
          Next
    
          'display properties collection for Tabledef
          For Each MyProperty In MyTableDef.Properties
             List3.AddItem MyProperty.Name
          Next
    
          'Append an application-defined TableDef property by
          'changing its default value so it appears in the list
          On Error GoTo myerr:     'if RowHeight property exists trap error
          Set MyProperty = MyTableDef.CreateProperty("RowHeight")
          MyProperty.Type = dbinteger
          MyProperty.Value = 9
          MyTableDef.Properties.Append MyProperty
    
          myerr:
          MsgBox("RowHeight Property already exists, Please create another")
    
          'Print list again to see that RowHeight is displayed
          For Each MyProperty In MyTableDef.Properties
             List4.AddItem MyProperty.Name
          Next
          MySet.Close
          MyDb.Close
          On Error GoTo 0
    
    

  4. Add four list boxes (List1, List2, List3, and List4) to Form1.

  5. Run the program.
Keywords          : APrgDataAcc APrgDataIISAM APrgDataODBC VB4ALL VB4WIN vb5all
Version           : WINDOWS:4.0,5.0
Platform          : WINDOWS
Issue type        : kbinfo


================================================================================


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: December 12, 1997
© 1998 Microsoft Corporation. All rights reserved. Terms of Use.