Hide queries (1 Viewer)

aref

New member
Local time
Today, 19:10
Joined
Jan 10, 2023
Messages
27
Hello

I am using the following code to hide/show the tables

If I want to write the same code about queries, what will change?

so that they can be hidden by executing the query code.

Thanks

Function ShowHiddenObject(AttributesID As Integer)

Dim obj As AccessObject, dbs As Object

Set dbs = Application.CurrentData
Set db = CurrentDb

If AttributesID = 1 Then
For Each obj In dbs.AllTables
Set tdf = db.TableDefs(obj.Name)
If Left(tdf.Name, 4) <> "msys" And tdf.Attributes <> 1073741824 Then
tdf.Attributes = tdf.Attributes + dbHiddenObject
End If
Next

db.Close
Set db = Nothing
End If

If AttributesID = 2 Then
Set dbs = CurrentDb
For Each tdf In dbs.TableDefs
If Left(tdf.Name, 4) <> "msys" And tdf.Attributes <> 1073741824 _
And tdf.Attributes = 1 Then
tdf.Attributes = tdf.Attributes - dbHiddenObject
End If
Next tdf
Set dbs = Nothing
End If

Application.RefreshDatabaseWindow
End Function
 

The_Doc_Man

Immoderate Moderator
Staff member
Local time
Today, 13:10
Joined
Feb 28, 2001
Messages
27,192
You used "AllTables." The corresponding collection for queries is "AllQueries."

However, you should be aware that (given your previous question in AWF), this is pointless since if a user can see the navigation pane, they can exercise the option to "Show Hidden Objects."

This is not going to help you secure your database. You have to do something very different if your goal is to prevent users from meddling with your database structures and elements.
 

aref

New member
Local time
Today, 19:10
Joined
Jan 10, 2023
Messages
27
thank you

I know that it does not provide security

I want to do this by coding to learn
 

isladogs

MVP / VIP
Local time
Today, 19:10
Joined
Jan 14, 2017
Messages
18,239
The code above only works for tables. There is no equivalent code to hide queries
 

Users who are viewing this thread

Top Bottom