Microsoft KB Archive/209841

= ACC2000: How to Use Visual Basic to Hide a Link to an External Table =

Article ID: 209841

Article Last Modified on 6/23/2005

-

APPLIES TO


 * Microsoft Access 2000 Standard Edition

-



This article was previously published under Q209841



Moderate: Requires basic macro, coding, and interoperability skills.

This article applies only to a Microsoft Access database (.mdb).



SUMMARY
This article shows how you can use Visual Basic for Applications to create a link to an external table, and to then hide the link in the current database. You do this by creating a new table, creating the link to the external table, and then setting the hidden attribute of the newly created table to True.



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. NOTE: The sample code in this article uses Microsoft Data Access Objects. For this code to run properly, you must reference the Microsoft DAO 3.6 Object Library. To do so, click References on the Tools menu in the Visual Basic Editor, and make sure that the Microsoft DAO 3.6 Object Library check box is selected.

The following Visual Basic for Applications procedure creates a new table (NewTable) in the current database, and then links it to the Customers table in the sample database Northwind.mdb. Finally, it sets the hidden attribute of the NewTable table to True so that the table is hidden in the current database.

Creating, Linking, and Hiding the Table
 Start Microsoft Access and create a new database, Db1.mdb. Create a module, and then type the following line in the Declarations section if it is not already there:

Option Explicit

  Type or paste the following procedure: Function MakeHiddenAttachedTable(strDatabaseName As String, _        strTableName As String, strAttachedTableName As String)

Dim db As DAO.Database Dim td As DAO.TableDef

Set db = CurrentDb Set td = db.CreateTableDef(strAttachedTableName)

td.Connect = ";Database=" & strDatabaseName td.SourceTableName = strTableName db.TableDefs.Append td  td.Attributes = dbHiddenObject

Set td = Nothing Set db = Nothing

End Function

 To test this function, press CTRL+G to open the Immediate window, type the following line, and then press ENTER:

?MakeHiddenAttachedTable("C:\Program Files\Microsoft Office\Office\Samples\Northwind.mdb", "Customers", "NewTable")

A new hidden table, named NewTable, that links to the Customers table in the Northwind database is created.

NOTE: This example assumes that your sample database Northwind.mdb is saved in the following location:

C:\Program Files\Microsoft Office\Office\Samples\



Delete the NewTable Table
To use a Visual Basic for Applications procedure to delete a hidden linked table in the sample database Northwind.mdb, follow these steps:  Start Microsoft Access, and then open the Db1.mdb database created in the previous example.</li> Create a module, and then type the following line in the Declarations section if it is not already there:

Option Explicit

</li>  Type or paste the following procedure: Function DeleteHiddenAttachedTable(strAttachedTableName As String)

Dim db As DAO.Database Set db = CurrentDb

db.TableDefs.Delete strAttachedTableName

End Function </li> To test this function, type the following line in the Immediate window, and then press ENTER.

?DeleteHiddenAttachedTable("NewTable")

Notice that the new hidden table, NewTable, is deleted.</li></ol>

Additional query words: link attach attached invisible

Keywords: kbhowto kbinfo KB209841

-

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

© Microsoft Corporation. All rights reserved.