Solved

How to check if a query is hidden from within a VBA module?

Posted on 2006-07-19
13
256 Views
Last Modified: 2006-11-18
Hi,
I am building up a table of all queries that are in my database. I don't want to list hidden queries, but I cannot find a way of checking for hidden queries within the code. Any ideas?

This is the snippet of code I use to go through the CurrentData's AllQueries collection:

---
        ' go through all the queries
        For Each aob In CurrentData.AllQueries
            rst.AddNew
           
            ' get the name and type
            rst!objName = aob.Name
            rst!objType = "Query"
            intNum = intNum + 1
            rst!objNo = intNum
           
            ' is it hidden?
            ' ????
           
            ' done!
            rst.Update
        Next aob
---
Thanks!
Andy
0
Comment
Question by:acotgreave
  • 7
  • 5
13 Comments
 
LVL 65

Expert Comment

by:rockiroads
ID: 17136861
try checking the atttributes, if hidden dont do it
e.g.

    For Each aob In CurrentData.AllQueries
         if aob.Attributes = 8 then
            rst.AddNew
           
            ' get the name and type
            rst!objName = aob.Name
            rst!objType = "Query"
            intNum = intNum + 1
            rst!objNo = intNum
           
            ' is it hidden?
            ' ????
           
            ' done!
            rst.Update
        End if
    Next aob
0
 

Author Comment

by:acotgreave
ID: 17136889
Hmm, that was easy!

Almost a perfect answer: 8 IS hidden, so I need to check for inequality when checking it.

The Attributes property doesn't appear in the Intellisense drop down when I am writing the code. Is it undocumented? And why 8? Do you know what the other attributes are?

Thanks for the answer - it's just what I needed to know!

Andy
0
 

Author Comment

by:acotgreave
ID: 17136961
Um, there's a problem.

8 is the attribute for a hidden basic SELECT query. If it's an Update, Append, Crosstab, then the number is different.

I can see that the 8-bit is set for hidden, Crosstab is 16, and Append is 64, for example.

I'm not experienced at bitmasking, particularly in Access - do you know a way to mask the attribute value so that i just get the hidden bit?

Andy
0
 
LVL 65

Expert Comment

by:rockiroads
ID: 17136964
oops, thats what I meant to do!

But u sussed it out anyway


Attributes, perhaps its added for backwards compatability, I dont know

Did u define aob as AccessObject

You may be able to make use of the .Type property

I dont know all the values for the other possible types
0
 
LVL 65

Accepted Solution

by:
rockiroads earned 400 total points
ID: 17136981
bitmasking u do this

aob.Attibutes & 8 = 8 then ...

but this wont work as it will pickup non hidden queries
0
 
LVL 65

Expert Comment

by:rockiroads
ID: 17137030
Im going thru the query properties but cannot find anything

Public Sub dgdgd()

    Dim aob As DAO.QueryDef
    Dim i As Integer
   
    On Error Resume Next
   
    For Each aob In CurrentDb.QueryDefs
        If Left(aob.Name, 1) <> "~" Then
            Debug.Print aob.Name
            For i = 0 To aob.Properties.Count - 1
                Debug.Print aob.Properties(i).Name, aob.Properties(i).Value
            Next i
        End If
    Next aob

   
End Sub
0
Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

 
LVL 65

Expert Comment

by:rockiroads
ID: 17137089
ok, it seems it adds values e.g

query that had attribute of 64, if you hide it, it becomes 72

so I guess we could see if number is divisible by 8 and the divisble value is even
if so then its not hidden. What do u think
0
 

Author Comment

by:acotgreave
ID: 17137139
What I've done is add ALL objects to the table, and now added the attributes value to the table, too.

I run a query on the table to display only the non-hidden queries. I have added a user-defined function that checks the 8-bit is set:

---
Function TestHiddenBitMask(a As Variant) As Boolean
    Dim constHidden As Integer
    constHidden = 8
   
    TestHiddenBitMask = ((a And constHidden) = constHidden)
End Function
---

My select query is now:

---
SELECT objNo, objName, objType, objAttributes
FROM tblObjects
WHERE (((objType)="Query") AND ((objAttributes)=TestHiddenBitMask([objAttributes])))
ORDER BY objName;
---

This calls the UDF and it _should_ return true if the 8-bit is set. But it's not quite there, it only returns 24 objects, and my database has 37 non-hidden queries! I feel like I am nearly there, but haven't yet seen the problem in my UDF.

Any ideas?
0
 

Author Comment

by:acotgreave
ID: 17137157
I cracked it! It was an error in the SQL statement - I needed to explicitly check that the UDF returned False.
---
SELECT tblObjects.objNo, tblObjects.objName, tblObjects.objType, tblObjects.objAttributes
FROM tblObjects
WHERE (((tblObjects.objType)="Query") AND (TestHiddenBitMask([objAttributes])=False))
ORDER BY tblObjects.objName;
---

I have also changed the UDF so it is more generic, and can check any bitmask (the SQL string above does not reflect this change):

Function TestHiddenBitMask(a As Variant, constHidden As Variant) As Boolean
    TestHiddenBitMask = ((CLng(a) And CLng(constHidden)) = CLng(constHidden))
End Function

I am sure you could repeat this in the query builder, though? Thing is, I'm more comfortable in VBA than the Access query builder UI....
Any idea how to do the same in the query builder? Don't worry if you don't know - I've got my solution!

Andy
0
 
LVL 65

Expert Comment

by:rockiroads
ID: 17137422
And that is working for you?
Reason why I ask is
If type is 64, it reports it as Hidden


Public Sub ListQ()

    Dim aob As AccessObject
   
    For Each aob In CurrentData.AllQueries
   
        If aob.Attributes > 0 Then
            If aob.Attributes And 8 = 8 Then Debug.Print "HIDDEN", aob.Name, aob.Attributes
        End If
    Next
End Sub

0
 
LVL 65

Expert Comment

by:rockiroads
ID: 17137425
Did u have problems with EE? Ive been unable to get in for quite a while
0
 

Author Comment

by:acotgreave
ID: 17137449
It works for me. If it's 64, the test evaluates to:
(64 And 8) = 8

Type that in the Immediate window - ? (64 And 8) = 8) - and the result is false. Which is good, coz 64 is a non-hidden Append query. If you hide it, it's attributes become 72
? (72 And 8) = 8
which returns True.

[no EE problems for me, but then I've been away from my desk for 90 minutes!]
0

Featured Post

Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

Join & Write a Comment

Regardless of which version on MS Access you are using, one of the harder data-entry forms to create is one where most data from previous entries needs to be appended to new records, especially when there are numerous fields and records involved.  W…
Experts-Exchange is a great place to come for help with solutions for your database issues, and many problems are resolved within minutes of being posted.  Others take a little more time and effort and often providing a sample database is very helpf…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
Using Microsoft Access, learn some simple rules for how to construct tables in a relational database. Split up all multi-value fields into single values: Split up fields that belong to other things into separate tables: Make sure that all record…

744 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now