ACC: How to Use the Attributes Property for TableDef Objects

ID: Q117536

The information in this article applies to:

SUMMARY

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

You can use the Attributes property of a TableDef object to determine specific table properties. For example, you can use the Attributes property to find whether a table is a system table or a linked (attached) table.

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

The Attributes property of a TableDef object specifies characteristics of the table represented by the TableDef object. The Attributes property is stored as a single Long number and is the sum of the following Long constants:

NOTE: In Microsoft Access 2.0, add an underline (_) after the letters db when you use any of these constants. For example, dbAttachExclusive becomes db_AttachExclusive in version 2.0.

   Constant            Description
   ----------------------------------------------------------------------
   dbAttachExclusive   For databases that use the Microsoft Jet database
                       engine, indicates the table is a linked table
                       opened for exclusive use.
   dbAttachSavePWD     For databases that use the Jet database engine,
                       indicates the user ID and password for the
                       linked table should be saved with the connection
                       information.
   dbSystemObject      Indicates the table is a system table.
   dbHiddenObject      Indicates the table is a hidden table (for
                       temporary use).
   dbAttachedTable     Indicates the table is a linked table from a
                       non-Open Database Connectivity (ODBC) database,
                       such as Microsoft Access or Paradox.
   dbAttachedODBC      Indicates the table is a linked table from an
                       ODBC database, such as Microsoft SQL Server or
                       ORACLE Server.

For a TableDef object, use of the Attributes property depends on the status of TableDef, as the following table shows:

   TableDef                            Usage
   ---------------------------------   ----------
   Object not appended to collection   Read/write
   Base table                          Read-only
   Linked table                        Read-only

When checking the setting of this property, you can use the AND operator to test for a specific attribute. For example, to determine whether a table object is a system table, perform a logical comparison of the TableDef Attributes property and the dbSystemObject constant.

Sample Code

The following user-defined sample function loops through all the tables in a database and displays a message box listing each table name and whether or not the table is a system table:

   Option Compare Database   'Use database order for string comparisons.

   Option Explicit

   Function ShowTableAttribs()
      Dim DB As Database
      Dim T As TableDef
      Dim TType As String
      Dim TName As String
      Dim Attrib As String
      Dim I As Integer

      Set DB = CurrentDB()

      For I = 0 To DB.Tabledefs.Count - 1
         Set T = DB.Tabledefs(I)
         TName = T.Name
         Attrib = (T.Attributes And dbSystemObject)
         MsgBox TName & IIf(Attrib, ": System Table", ": Not System Table")
      Next I
   End Function

REFERENCES

For more information about the Attributes property, search the Help Index for "Attributes."

Additional query words: dao

Keywords          : kbprg PgmObj 
Version           : 2.0 7.0 97
Platform          : WINDOWS
Hardware          : x86
Issue type        : kbhowto

Last Reviewed: November 21, 1998