Question : Hide and Unhide tables, queries, forms, code, etc

Hi Experts,

I don't know where I get this code from, but I tried to test it, it gives a "Object invalid or no longer set" error.

I have a table that store all the login ids that mapped to either "Admin" or "User", if the person's intranet login indicates he/she is a "User", then all tables/queries/forms/code needs to be hidden, else they are visible.

Can anyone direct me on how to accomplish this?

Thanks in advance~
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
Public Sub HideUnhide(blHidden As Boolean)

    Dim i As Integer
    
    With CurrentDb.Containers("Forms")
        For i = 0 To .Documents.Count - 1
            If .Documents(i).Name <> "Switchboard" Then
                Application.SetHiddenAttribute acForm, .Documents(i).Name, blHidden
            End If
        Next
    End With

    With CurrentDb.Containers("Modules")
        For i = 0 To .Documents.Count - 1
            Application.SetHiddenAttribute acModule, .Documents(i).Name, blHidden
        Next
    End With

    With CurrentDb.Containers("Tables")
        For i = 0 To .Documents.Count - 1
            Application.SetHiddenAttribute acTable, .Documents(i).Name, blHidden
        Next
    End With

    With CurrentDb.Containers("Queries")
        For i = 0 To .Documents.Count - 1
            Application.SetHiddenAttribute acQuery, .Documents(i).Name, blHidden
        Next
    End With

End Sub

Answer : Hide and Unhide tables, queries, forms, code, etc

try this

1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
Public Sub HideUnhide(blHidden As Boolean)
    
    Dim i As Integer, db As DAO.Database
    Set db = CurrentDb
    
    With db.Containers("Forms")
        For i = 0 To .Documents.Count - 1
            If .Documents(i).Name <> "Switchboard" Then
                Application.SetHiddenAttribute acForm, .Documents(i).Name, blHidden
            End If
        Next
    End With

    With db.Containers("Modules")
        For i = 0 To .Documents.Count - 1
            Application.SetHiddenAttribute acModule, .Documents(i).Name, blHidden
        Next
    End With

    With db.Containers("Tables")
        For i = 0 To .Documents.Count - 1
            If .Documents(i).Name Like "msys*" Or .Documents(i).Name Like "~*" Then
            Else
            Application.SetHiddenAttribute acTable, .Documents(i).Name, blHidden
            End If
        Next
    End With

    With db.Containers("Queries")
        For i = 0 To .Documents.Count - 1
            Application.SetHiddenAttribute acQuery, .Documents(i).Name, blHidden
        Next
    End With

End Sub
Random Solutions  
 
programming4us programming4us