Solved

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

Posted on 2006-07-19
13
284 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
Enterprise Mobility and BYOD For Dummies

Like “For Dummies” books, you can read this in whatever order you choose and learn about mobility and BYOD; and how to put a competitive mobile infrastructure in place. Developed for SMBs and large enterprises alike, you will find helpful use cases, planning, and implementation.

 
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

Migrating Your Company's PCs

To keep pace with competitors, businesses must keep employees productive, and that means providing them with the latest technology. This document provides the tips and tricks you need to help you migrate an outdated PC fleet to new desktops, laptops, and tablets.

Question has a verified solution.

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

A simple tool to export all objects of two Access files as text and compare it with Meld, a free diff tool.
Preparing an email is something we should all take special care with – especially when the email is for somebody you may not know very well. The pressures of everyday working life stacked with a hectic office environment can make this a real challen…
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…
In Microsoft Access, when working with VBA, learn some techniques for writing readable and easily maintained code.

740 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