Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Shaun E on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

how to hide/unhide queries with VBA 1

Status
Not open for further replies.

jbpez

Programmer
Jan 25, 2005
102
I know how to hide/unhide tables:

For Each tdf In CurrentDb.TableDefs
tdf.Attributes = dbHiddenObject
Next tdf

but queries,

For Each qdf In CurrentDb.QueryDefs
qdf.Attributes = dbHiddenObject
Next qdf

does not work.

Can this be done with VBA ? If so, how ?
 
Just a guess as I don't have access at hand today:
Try to create a query named USysSomething and see if it becomes hidden.

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ222-2244
 
Or try the sethiddenattribute method of the application object:

[tt]application.sethiddenattribute acquery, qdf.name, true[/tt]

Roy-Vidar
 
PHV, USysQueryName does work, however it is not done using VBA.

RoyVidar, thanks for the suggestion it works with CurrentDb.

My new question is - Why does it work with CurrentDb and not with a remote database.

Example:
Set db = OpenDatabase("C:\My Documents\Test.mde")

For Each qdf In db.QueryDefs
If qdf.Name Like "~*" Then
Else
Application.SetHiddenAttribute acQuery, qdf.Name, True
End If
Next qdf
 
Application here refers to the current database, you'll need something referring to the other database, i e (this can probably be done much more elegant)

[tt]dim acc as access.application
set acc=createobject("access.application")
acc.opencurrentdatabase ("C:\My Documents\Test.mde")
For Each qdf In acc.currentdb.QueryDefs
If qdf.Name Like "~*" Then
Else
acc.Application.SetHiddenAttribute acQuery, qdf.Name, True
End If
Next qdf[/tt]

But I'm not sure how this would work on an mde, though...

Roy-Vidar
 
Thanks RoyVidar, it works great.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top