Microsoft KB Archive/129732

= INFO: Data Access Objects Have Properties Based on Database Type =

Article ID: 129732

Article Last Modified on 5/6/2003

-

APPLIES TO


 * Microsoft Visual Basic 6.0 Learning Edition
 * Microsoft Visual Basic 6.0 Professional Edition
 * Microsoft Visual Basic 6.0 Enterprise Edition
 * Microsoft Visual Basic 5.0 Professional Edition
 * Microsoft Visual Basic 5.0 Enterprise Edition
 * Microsoft Visual Basic 4.0 Professional Edition
 * Microsoft Visual Basic 4.0 Professional Edition
 * Microsoft Visual Basic 4.0 16-bit Enterprise Edition
 * Microsoft Visual Basic 4.0 32-Bit Enterprise Edition

-



This article was previously published under Q129732



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
 Start a new project in Visual Basic. Form1 is created by default. If using Visual Basic 5.0, establish a reference to DAO 3.5 by clicking References from the Project menu.  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

 Add four list boxes (List1, List2, List3, and List4) to Form1. Run the program.

Additional query words: kbVBp400 kbVBp500 kbVBp600 kbdse kbDSupport kbVBp

Keywords: kbinfo KB129732

-

[mailto:TECHNET@MICROSOFT.COM Send feedback to Microsoft]

© Microsoft Corporation. All rights reserved.