Full Version: Can I hide queries
UtterAccess Discussion Forums > Microsoft® Access > Access Reports
PropMgr
I am using the following code to hide table from the object brouser for my data base works well
Have a table tblTableList and loop through this and hide the tables with a boolean value, hide table stet to true or -1

Can I do something similar with my queries?



Private Sub cmdHideTables_Click()

'Hide a table from the database window
'Note: This is different than the Access Object
'hidden''attribute that can be set with SetHiddenAttribute

On Error GoTo cmdHideTables_Click_Err
Dim rst As DAO.Recordset ' table list
Dim strTblList As String
Dim strTblName As String
Dim intTableCount As Integer
Dim lngAttributes As Long

Set db = CurrentDb()
Set rst = db.OpenRecordset("tblTableList", dbOpenSnapshot)
intTableCount = 0
Subjectline = InputBox("Please enter a password to confirm hiding of tables.", _
"Sac City Property Management")

If Subjectline = "123" Then

With rst
' Me.Recordset.Requery

rst.MoveFirst
Do Until rst.EOF = True
If rst!HideTable = -1 Then

intTableCount = intTableCount + 1
strTblName = rst!TableName
strTblList = strTblList & strTblName & ", "


With db.TableDefs(strTblName)

'Take a snapshot of the current bit fields
lngAttributes = .Attributes

'Now UNSET the ReadOnly bits in the SnapShot
'so we don't try to write to them.
lngAttributes = lngAttributes Or dbAttachedODBC
lngAttributes = lngAttributes Or dbAttachedTable
lngAttributes = lngAttributes - (dbAttachedODBC + dbAttachedTable)
'Now set the hidden bit, while maintaining the other
'writable bits
.Attributes = lngAttributes Or dbHiddenObject

End With
End If

rst.MoveNext
Loop

End With

MsgBox "The following table have been hidden: " & intTableCount & " " & vbCrLf & strTblList
'Reflect the change in the database window/nav pane
RefreshDatabaseWindow

Else 'Password is wrong
MsgBox "Password incorect"

End If
HiTechCoach
I just recently help someone wanting to do the same thing.

Here is one way:
CODE
Function HideQuerys()

Dim qry As QueryDef

    Dim x As Integer



    For Each qry In CurrentDb.QueryDefs



        If Left(qry.Name, 1) <> "~" Then

            If Not Left(qry.Name, 4) = "Usys" Then

                qry.Name = "Usys" & qry.Name

            End If

        End If

    Next

End Function


Note: With forms and reports, you can store the SQL in the record source property for even more security.

Also, you can store the SQL for querio4es in a hidden table.
HiTechCoach
I searched the Access Code Archive forum and found this:

Using Queries/SQL statements stored in a table
PropMgr
Wow, I like that idea!

Storing Queries in tables, sounds way cool. let me look into that and I will get back to you.

Thanks ever so much

Michael
This is a "lo-fi" version of our main content. To view the full version with more information, formatting and images, please click here.