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



The information in this article applies to:

  • Microsoft Access for Windows 95 7.0
  • Microsoft Access 97

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

SUMMARY

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. 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 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:
    Option Explicit
    					
  3. Type the following procedure:
          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
    					
  4. 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:
    Option Explicit
    					
  3. Type the following procedure:
          Function DeleteHiddenAttachedTable(strAttachedTableName As String)
    
             Dim db As Database
             Set db = CurrentDb
    
             db.TableDefs.Delete strAttachedTableName
    
          End Function
    					
  4. 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.

Modification Type:MinorLast Reviewed:10/11/2006
Keywords:kbhowto kbProgramming KB188801