Solved

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

Posted on 2006-07-19
13
298 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
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!

 
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

Instantly Create Instructional Tutorials

Contextual Guidance at the moment of need helps your employees adopt to new software or processes instantly. Boost knowledge retention and employee engagement step-by-step with one easy solution.

Question has a verified solution.

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

Access custom database properties are useful for storing miscellaneous bits of information in a format that persists through database closing and reopening.  This article shows how to create and use them.
This article describes a method of delivering Word templates for use in merging Access data to Word documents, that requires no computer knowledge on the part of the recipient -- the templates are saved in table fields, and are extracted and install…
Familiarize people with the process of retrieving data from SQL Server using an Access pass-thru query. Microsoft Access is a very powerful client/server development tool. One of the ways that you can retrieve data from a SQL Server is by using a pa…
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…

728 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