Notice: This website is an unofficial Microsoft Knowledge Base (hereinafter KB) archive and is intended to provide a reliable access to deleted content from Microsoft KB. All KB articles are owned by Microsoft Corporation. Read full disclaimer for more details.

ACC2000: Cannot Set Attributes Property in Visual Basic Code


View products that this article applies to.

This article was previously published under Q198645
Moderate: Requires basic macro, coding, and interoperability skills.

↑ Back to the top


Summary

When you use the CreateTableDef method to create a table that is linked to a table in another Microsoft Access database or to an ODBC data source, you cannot set the Attributes property to dbAttachedTable or dbAttachedODBC. These constants are always read-only. When you create the linked table, you must set the Connect property and the SourceTableName property. This automatically sets the Attributes property to dbAttachedTable or to dbAttachedODBC, whichever is appropriate. However, you can set the Attributes property to dbAttachExclusive or dbAttachSavePWD.

After you have appended the table to the database, the Attributes property is read-only.

↑ Back to the top


More information

Microsoft provides programming examples for illustration only, without warranty either expressed or implied. This includes, but is not limited to, the implied warranties of merchantability or fitness for a particular purpose. This article assumes that you are familiar with the programming language that is being demonstrated and with the tools that are used to create and to debug procedures. Microsoft support engineers can help explain the functionality of a particular procedure, but they will not modify these examples to provide added functionality or construct procedures to meet your specific requirements. The following sample procedure creates a linked table whose Attributes property is set to dbAttachedTable:
  1. Start Access and create a blank database.
  2. Create a new module and type the following line in the Declarations section if it is not already there:
    Option Explicit
    					
  3. On the Tools menu, click References, and in the Available References list, click to select Microsoft DAO 3.6 Object Library.
  4. Type the following procedure:
    Sub CreateLinkedTable()
    
       Dim dbLocal As DAO.Database
       Dim tbfNewAttached As DAO.TableDef
    
       Set dbLocal = CurrentDb()
       Set tbfNewAttached = dbLocal.CreateTableDef("MyEmp")
    
       With tbfNewAttached
         .Connect = ";database=<your path to Northwind>"
         .SourceTableName = "Employees"
       End With
    
       dbLocal.TableDefs.Append tbfNewAttached
    
    End Sub
    					
  5. To test this function, type the following line in the Immediate window, and then press ENTER:
    CreateLinkedTable
    					
    Note that the new linked table is shared.
To test the Attributes property of the new table, type the following line in the Immediate window, and then press ENTER:
?currentdb.TableDefs("MyEmp").Attributes = dbAttachedTable
				
This returns the value True to the Immediate window.

To create a table that is linked exclusively, change the With...End With statement in the procedure in step 3 to the following:
With tbfNewAttached
   .Connect = ";database=<your path to Northwind>"
   .SourceTableName = "Employees"
   .Attributes = dbAttachExclusive
End With
				
To test the Attributes property of this table, type the following on a single line in the Immediate window, and then press ENTER:
?currentdb.TableDefs("MyEmp").Attributes = dbAttachedTable + dbAttachExclusive
				
The following sample With...End With statement sets the properties of a table linked to an ODBC DSN named "sqltest"; the table is linked to a table named dbo_employee in the remote data source.

Note In the following sample code, you must change UID=<username> and PWD=<strong password> to the correct values. Make sure that the user ID has the appropriate permissions to perform this operation on the database.
With tbfNewAttached
   .Connect = "ODBC;DSN=sqltest;UID=<username>;PWD=<strong password>"
   .SourceTableName = "employee"
End With
				
To test the Attributes property of this table, type the following line in the Immediate window, and then press ENTER:
?currentdb.TableDefs("MyEmp").Attributes = dbAttachedODBC
				

↑ Back to the top


References

For more information about the Attributes property, in the Visual Basic Editor, click Microsoft Visual Basic Help on the Help menu, type Attributes Property in the Office Assistant or the Answer Wizard, and then click Search to view the topic.

↑ Back to the top


Keywords: KB198645, kbprogramming, kbinfo

↑ Back to the top

Article Info
Article ID : 198645
Revision : 6
Created on : 10/11/2006
Published on : 10/11/2006
Exists online : False
Views : 350