ACC: Using Visual Basic to Hide a Link to an External Table

ID: Q188801


The information in this article applies to:
  • Microsoft Access versions 7.0, 97


SUMMARY

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

This article shows you how you can use Visual Basic for Applications to link an external table but to hide the link on your local computer. 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, including, but not limited to, the implied warranties of merchantability and/or fitness for a particular purpose. This article assumes that you are familiar with the programming language being demonstrated and the tools used to create and debug procedures. Microsoft support professionals 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 needs. If you have limited programming experience, you may want to contact a Microsoft Certified Solution Provider or the Microsoft fee-based consulting line at (800) 936-5200. For more information about Microsoft Certified Solution Providers, please see the following page on the World Wide Web:

http://www.microsoft.com/mcsp/
For more information about the support options available from Microsoft, please see the following page on the World Wide Web:

http://www.microsoft.com/support/supportnet/overview/overview.asp
The following Visual Basic for Applications procedure use the sample database Northwind.mdb to create a new table (New Table); it then links the new table to an external table (the Examples table in the sample database Solutions.mdb); and finally, it sets the hidden attribute of the new table to True so that the table is hidden on the local computer.

Creating, Linking, and Hiding the Table

  1. Start Microsoft Access and open the sample database Northwind.mdb.


  2. Create a module and type the following line in the Declarations section if it is not already there:


  3. 
    Option Explicit 
  4. Type the following procedure:


  5. 
          Function MakeHiddenAttachedTable(strDatabaseName As String, _
                   strTableName As String, strAttachedTableName As String)
    
             Dim db As Database
             Dim td As 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 
  6. To test this function, type the following line in the Debug window, and then press ENTER:
    
    ?MakeHiddenAttachedTable ("Solutions", "Examples", "New Table") 
    A new hidden table named New Table that links the Examples table in the Solutions database is created.


Delete the New Table Table

The following steps demonstrate how to use a Visual Basic for Applications procedure to delete a hidden linked table in the sample database Northwind.mdb:
  1. Start Microsoft Access and open the sample database Northwind.mdb.


  2. Create a module and type the following line in the Declarations section if it is not already there:


  3. 
    Option Explicit 
  4. Type the following procedure:


  5. 
          Function DeleteHiddenAttachedTable(strAttachedTableName As String)
    
             Dim db As Database
             Set db = CurrentDb
    
             db.TableDefs.Delete strAttachedTableName
    
          End Function 
  6. To test this function, type the following line in the Debug window, and then press ENTER:
    
    ?DeleteHiddenAttachedTable("New Table") 
    The new hidden table, New Table, is deleted.


Additional query words: inf link attach attached

Keywords : kbdta AccCon TblHowto KbVBA
Version : WINDOWS:7.0,97
Platform : WINDOWS
Issue type : kbhowto


Last Reviewed: July 6, 1999
© 2000 Microsoft Corporation. All rights reserved. Terms of Use.