the following code will hide/show the tables in a db by changing each
table's attributes to make it a system table - or not. for obvious reasons,
the MSys tables are explicitly exempted from being changed in the code. if
you only want to show/hide specific tables, you can modify the code to use a
collection, where you list specific table names, instead of looping through
all the tables in the db.
Public Function isSetTableProperties(ByVal str As String)
Dim dbs As DAO.Database, tbl As DAO.TableDef
Set dbs = CurrentDb
For Each tbl In dbs.TableDefs
If Not Left(tbl.Name, 4) = "MSys" Then
If str = "hide" Then
If tbl.Attributes = 0 Then tbl.Attributes = dbSystemObject
If (tbl.Attributes And dbAttachedTable) Then
If Not (tbl.Attributes And dbSystemObject) Then
tbl.Attributes = dbSystemObject
End If
ElseIf str = "show" Then
If tbl.Attributes = dbSystemObject Then tbl.Attributes = 0
If (tbl.Attributes And dbAttachedTable) Then
If (tbl.Attributes And dbSystemObject) Then
tbl.Attributes = 0
End If
End If
End If
Next
End Function
call the function wherever you need it, example
isSetTableProperties "hide"
you can also run code when the database opens, to set the ShowSystemObjects
option to False, as follows
Public Function isSetAttributes(ByVal str As String, ByVal bln As Boolean)
If Application.GetOption(str) = (Not bln) Then Application.SetOption
str, bln
End Function
and call it as
isSetAttributes "Show System Objects", False
so you can make Access treat the tables as system objects, and then make
sure the database opens with system objects hidden. i didn't write this
code, btw, i got it from Garry Robinson's book Real World Microsoft Access
Database Protection and Security. and it does work in A97; i tested it again
(since i haven't been using it) and then copied it, from my own working A97
db. and one more note: when a local table attribute is set to make it a
"system object", the table becomes read-only *when you open the table
directly*. but you can open a query based on the table and add/edit/delete
records, and do the same in a form based on the query. this "read-only"
status does not apply to linked tables, only to local tables.
hth