 |
Access VBA Discuss using VBA for Access programming. |
Welcome to the p2p.wrox.com Forums.
You are currently viewing the Access VBA section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
|
|
|

April 26th, 2005, 09:09 PM
|
Authorized User
|
|
Join Date: Jun 2004
Posts: 15
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Hiding Objects In A2K
This code was shown by another forum several years ago and I have a use for it now, but I need more info. This code hides table and query objects and I am looking for a way to code it to hide forms, reports, macros and modules. Can anyone help me?
Code:
Function HideAll2K()
On Error Resume Next
Dim tdf As DAO.TableDef
For Each tdf In CurrentDb.TableDefs
If Left(tdf.Name, 1) <> "_" Then
Application.SetHiddenAttribute acTable, tdf.Name, True
End If
Next tdf
Dim qdf As DAO.QueryDef
For Each qdf In CurrentDb.QueryDefs
If Left(qdf.Name, 1) <> "_" Then
Application.SetHiddenAttribute acQuery, qdf.Name, True
End If
Next qdf
Dim obj As AccessObject
Dim dbs As Object
Set dbs = Application.CurrentProject
' Search for open AccessObject objects in AllForms collection.
For Each obj In dbs.AllForms
If Left(obj.Name, 1) <> "_" Then
Application.SetHiddenAttribute acForm, obj.Name, True
End If
Next obj
For Each obj In dbs.AllModules
If Left(obj.Name, 1) <> "_" Then
Application.SetHiddenAttribute acModule, obj.Name, True
End If
Next obj
For Each obj In dbs.AllMacros
If Left(obj.Name, 1) <> "_" Then
Application.SetHiddenAttribute acMacro, obj.Name, True
End If
Next obj
End Function
Thanks,
PC
|

April 29th, 2005, 07:23 AM
|
Friend of Wrox
|
|
Join Date: Nov 2004
Posts: 248
Thanks: 0
Thanked 1 Time in 1 Post
|
|
This code will actually hide almost all of the Access objects.
If you want to hide ALL forms (and modules and macros), simply remove the
Code:
If Left(obj.Name, 1) <> "_" Then
...
End If
from the:
Code:
For Each obj In dbs.xxxx
...
Next obj
Obviously the author only wanted to hide forms (and modules and macros) if the name begins with an underscore.
To hide reports add:
Code:
For Each obj In dbs.AllReports
Application.SetHiddenAttribute acReport, obj.Name, True
Next obj
Randall J Weers
Membership Vice President
Pacific NorthWest Access Developers Group
http://www.pnwadg.org
|

May 4th, 2005, 12:11 PM
|
Authorized User
|
|
Join Date: Jun 2004
Posts: 15
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Thanks for your reply. I've changed my code to:
Code:
Option Compare Database
Option Explicit
Dim tdf As DAO.TableDef
Dim qdf As DAO.QueryDef
Dim fdf As DAO.Document
Dim obj As AccessObject
Dim dbs As Object
Public Function HideAll2K()
On Error Resume Next
Set dbs = Application.CurrentProject
For Each tdf In CurrentDb.TableDefs
Application.SetHiddenAttribute acTable, tdf.Name, True
Next tdf
For Each qdf In CurrentDb.QueryDefs
Application.SetHiddenAttribute acQuery, qdf.Name, True
Next qdf
For Each fdf In CurrentDb.Containers
Application.SetHiddenAttribute acForm, fdf.Name, True
Next fdf
' Search for open AccessObject objects in AllTables collection.
For Each obj In dbs.AllTables
Application.SetHiddenAttribute acTable, obj.Name, True
Next obj
' Search for open AccessObject objects in AllQueries collection.
For Each obj In dbs.AllQueries
Application.SetHiddenAttribute acQuery, obj.Name, True
Next obj
' Search for open AccessObject objects in AllForms collection.
For Each obj In dbs.AllForms
Application.SetHiddenAttribute acForm, obj.Name, True
Next obj
' Search for open AccessObject objects in AllReports collection.
For Each obj In dbs.AllReports
Application.SetHiddenAttribute acReport, obj.Name, True
Next obj
' Search for open AccessObject objects in AllMacros collection.
For Each obj In dbs.AllMacros
Application.SetHiddenAttribute acMacro, obj.Name, True
Next obj
' Search for open AccessObject objects in AllModules collection.
For Each obj In dbs.AllModules
Application.SetHiddenAttribute acModule, obj.Name, True
Next obj
Application.SetOption "Show Hidden Objects", False
Application.SetOption "Show System Objects", False
Application.SetOption "ShowWindowsinTaskbar", False
End Function
Still only tables and queries are hidden. All else is still visible. Am I doing this right?
Thanks,
PC
|

May 5th, 2005, 06:44 AM
|
Friend of Wrox
|
|
Join Date: Nov 2004
Posts: 248
Thanks: 0
Thanked 1 Time in 1 Post
|
|
It looks to me like you are doing it right. Though it looks like you're running through the tables and queries twice. And I'm not sure what happens when you hide the Containers. And I'm not sure acForm is the correct value for hiding that.
Because you have "On Error Resume Next", you don't know if any of the code is having problems. You might try commenting out that line until you've debugged the code.
Once you get it all working, a possible modification might be to add a boolean parameter to your routine. I'll call the parameter pblnHide. Replace all of the "True"s with that parameter and all the "False"s with Not that parameter. E.g.
Public Function HideAll2K ( pblnHide as boolean )
Application.SetHiddenAttribute acTable, pblnHide
Application.SetOption "Show Hidden Objects", Not pblnHide
BTW, since you're not returning anything from the routine, you could call it a Sub instead of Function.
Public Sub HideAll2K ()
|
|
 |