Microsoft Access - Programmatically Hiding Tables Safely (Access 2000/2002)

Some time ago we ran a tip that discussed hiding objects in the Database window. As you may recall, you can hide an object by right-clicking on it, choosing Properties from the shortcut menu and then selecting the Hidden check box. One reader wrote in with concerns regarding concerns relating to a bug that can cause hidden tables to be deleted. First, be reassured that there's nothing to fear--the user interface technique we discussed is totally safe. The behavior that could cause tables to get deleted only comes into play when a table is hidden programmatically using DAO.

Although you shouldn't use DAO to programmatically hid tables, there is a safe way to programmatically hide them from view in the Database window--if you have Access 2000 or above. To do so, use the SetHiddenAttribute method. This method applies to the Application object and uses the syntax:

  • SetHiddenAttribute ObjectType, ObjectName, fHidden

Essentially, is the programmatic equivalent to the Hidden check box available through the user interface. The ObjectType argument accepts one of the standard AcObjectType constants (like acForm or acTable) and is used to indicate the type of object with which you're working. The ObjectName argument is simply the name of the object and fHidden accepts True or False to determine whether the object is hidden.

To illustrate, let's say that you have a database containing a table named tblOrders. You can use the following two procedures to programmatically change whether the table is visible in the Database window.

  • Sub HideTable()
  • Application.SetHiddenAttribute acTable, "tblOrders", True
  • End Sub
  • Sub ShowTable()
  • Application.SetHiddenAttribute acTable, "tblOrders", False
  • End Sub

  • Sub TableHiddenStatus()
  • Debug.Print Application.GetHiddenAttribute(acTable, "tblOrders")End Sub

Go back