Hide all access objects at once

S

Song Su

Access 2003; Windows XP

I disabled shift key for my frontend .mde. However, user still can create a
blank mdb and link to/import from my FE .mde tables which linked to BE mdb.

I want to hide tables and queries object in my FE .mde but I can only do one
object at a time (right click the object, property, hide). I have so many
tables and queries. Is it an easy way to hide them all at once?

thanks.
 
B

Barry Edmund Wright

Create a form called frmUtils and put a single button on it. In the
"On Click" event put the following:
=HidDBObjects()

In a code module put the following code:

Public Function HidDBObjects()
On Error GoTo Err_HidDBObjects

Dim vHid As Boolean
Dim vAnswer As String

vAnswer = MsgBox("Select ""Yes"" to Hid All DB Objects; Select ""No""
to Unhid All DB Objects!", vbQuestion + vbYesNoCancel, "Hid All DB
Objects")
If vAnswer = vbYes Then
vHid = True
ElseIf vAnswer = vbNo Then
vHid = False
ElseIf vAnswer = vbCancel Then
Exit Function
End If

Application.Echo False
HourGlass_On

If IsLoaded("frmUtils") = True Then
DoCmd.Close acForm, "frmUtils", acSaveYes
End If

HidTables vHid
HidFormsReportsMacros vHid

Application.Echo True
HourGlass_Off

Exit_HidDBObjects:
Exit Function

Err_HidDBObjects:
MsgBox Err.Description
Resume Exit_HidDBObjects

End Function

Public Function HidFormsReportsMacros(vbln As Boolean)

'Hids/Unhids all the forms, reports and macros in the database.
Dim obj As AccessObject
Dim dbs As Object
Set dbs = Application.CurrentProject

For Each obj In dbs.AllForms
Application.SetHiddenAttribute acForm, obj.Name, vbln
Next obj
For Each obj In dbs.AllReports
Application.SetHiddenAttribute acReport, obj.Name, vbln
Next obj
For Each obj In dbs.AllModules
Application.SetHiddenAttribute acModule, obj.Name, vbln
Next obj
For Each obj In dbs.AllMacros
Application.SetHiddenAttribute acMacro, obj.Name, vbln
Next obj

Set dbs = Application.CurrentData
For Each obj In dbs.AllQueries
Application.SetHiddenAttribute acQuery, obj.Name, vbln
Next obj

End Function

Public Function HidTables(vbln As Boolean)

Dim db As Database
Dim T As TableDef
Dim TName As String
Dim I As Integer
Dim vCnt As Integer

Set db = CurrentDb()

'Code below Hids or UnHids all non-system tables in a database.
For I = 0 To db.TableDefs.Count - 1
Set T = db.TableDefs(I)
TName = T.Name
If Not TName Like "msys*" Then
Application.SetHiddenAttribute acTable, TName, vbln
vCnt = vCnt + 1
End If
Next I

End Function
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top