Solved

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

Posted on 2006-07-19
13
301 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Salesforce Has Never Been Easier

Improve and reinforce salesforce training & adoption using WalkMe's digital adoption platform. Start saving on costly employee training by creating fast intuitive Walk-Thrus for Salesforce. Claim your Free Account Now

 
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
 
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

Salesforce Has Never Been Easier

Improve and reinforce salesforce training & adoption using WalkMe's digital adoption platform. Start saving on costly employee training by creating fast intuitive Walk-Thrus for Salesforce. Claim your Free Account Now

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

It’s the first day of March, the weather is starting to warm up and the excitement of the upcoming St. Patrick’s Day holiday can be felt throughout the world.
Access developers frequently have requirements to interact with Excel (import from or output to) in their applications.  You might be able to accomplish this with the TransferSpreadsheet and OutputTo methods, but in this series of articles I will di…
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…

626 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