Hide objects from Code

  • Thread starter Thread starter Shirley
  • Start date Start date
S

Shirley

I have a lot of tables/querys/forms that I need to hide
in database window. Setting up by clicking each perperty
is too much work. I'd like to do it through coding, one
click to get all of them hidden.

How to write the code?

Any help is greatly appreciated...

Thanks,

Shirely
 
"Shirley" said:
I have a lot of tables/querys/forms that I need to hide
in database window. Setting up by clicking each perperty
is too much work. I'd like to do it through coding, one
click to get all of them hidden.

How to write the code?

Any help is greatly appreciated...

Thanks,

Shirely

Shirley

I'm afraid that hiding objects, especially tables, via code is risky - you
stand a chance of them being deleted. I am afraid that you are going to have to
set the properties manually (although the time that it would take for the code
to be entered, checked on a sample database, debugged, etc, is probably more
than the time it would take to do this manually).
 
How about this?

Public Sub HideEverything()

Dim db As DAO.Database
Dim tdf As DAO.TableDef
Dim qdf As DAO.QueryDef
Dim obj As Object

On Error GoTo HandleErrors

Set db = CurrentDb

For Each tdf In db.TableDefs
Application.SetHiddenAttribute acTable, tdf.Name, True
Next

For Each qdf In db.QueryDefs
Application.SetHiddenAttribute acQuery, qdf.Name, True
Next

For Each obj In CurrentProject.AllForms
Application.SetHiddenAttribute acForm, obj.Name, True
Next

ExitHere:
Exit Sub

HandleErrors:
Select Case Err.Number
Case 2016 'Can't modify system tables
Resume Next
Case Else
MsgBox Err.Description & " (" & Err.Number & ")"
End Select
Resume ExitHere

End Sub
 
The other trick is to name your tables starting with the
string 'USys', those tables will be hidden just like the
MSys tables are hidden. This of course if you dont have
too much code depending on those names.
 
Back
Top