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.
- 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 DeleteHiddenAttachedTable(strAttachedTableName As String)
Dim db As DAO.Database
Set db = CurrentDb
db.TableDefs.Delete strAttachedTableName
End Function
- 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.