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: How to Use Visual Basic to Hide a Link to an External Table


View products that this article applies to.

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).

↑ Back to the top


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.

↑ 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. 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

  1. Start Microsoft Access and create a new database, Db1.mdb.
  2. Create a module, and then type the following line in the Declarations section if it is not already there:
    Option Explicit
  3. 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
    
    					
  4. 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:
  1. Start Microsoft Access, and then open the Db1.mdb database created in the previous example.
  2. Create a module, and then type the following line in the Declarations section if it is not already there:
    Option Explicit
  3. 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
    					
  4. 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.

↑ Back to the top


Keywords: KB209841, kbinfo, kbhowto

↑ Back to the top

Article Info
Article ID : 209841
Revision : 2
Created on : 6/23/2005
Published on : 6/23/2005
Exists online : False
Views : 366