Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

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

Posted on 2006-07-19
13
Medium Priority
?
305 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
Learn Veeam advantages over legacy backup

Every day, more and more legacy backup customers switch to Veeam. Technologies designed for the client-server era cannot restore any IT service running in the hybrid cloud within seconds. Learn top Veeam advantages over legacy backup and get Veeam for the price of your renewal

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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

AutoNumbers should increment automatically, without duplicates.  But sometimes something goes wrong, and the next AutoNumber value is a duplicate.  This article shows how to recover from this problem.
You need to know the location of the Office templates folder, so that when you create new templates, they are saved to that location, and thus are available for selection when creating new documents.  The steps to find the Templates folder path are …
With Microsoft Access, learn how to specify relationships between tables and set various options on the relationship. Add the tables: Create the relationship: Decide if you’re going to set referential integrity: Decide if you want cascade upda…
In Microsoft Access, when working with VBA, learn some techniques for writing readable and easily maintained code.

722 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