Print list of queries

Les Blair

Registered User.
Local time
Today, 10:16
Joined
Sep 10, 2007
Messages
49
Is there a way to print a list of all the queries that are part of a DataBase?
 
Do you mean print a list of the names of the queries, or auto print all of the data in each query?
 
You could make a table called tblQueryName, and run a report based on that after running this code to fill it:


Code:
Dim db As Database, qDef As QueryDef
Dim rs as Recordset

Set db = CurrentDb()
Set rs = db.OpenRecordset("tblQueryName")
  
  For Each qDef In db.QueryDefs
      rs.AddNew
      rs!QueryName = qDef.Name
      rs.Update
  Next qDef

That should give you a list of all queries in a table.
 
I just want a list of the names, but I am not sure how to use what you sent me. where do I put the code? do I define a tbl first?
 
You could make a table called tblQueryName, and run a report based on that after running this code to fill it:


Code:
Dim db As Database, qDef As QueryDef
Dim rs as Recordset

Set db = CurrentDb()
Set rs = db.OpenRecordset("tblQueryName")
  
  For Each qDef In db.QueryDefs
      rs.AddNew
      rs!QueryName = qDef.Name
      rs.Update
  Next qDef

That should give you a list of all queries in a table.


You don't need to create a table to get this. Just use this query:

Code:
SELECT Count(MSysObjects.Name) AS CountOfName
FROM MSysObjects
GROUP BY MSysObjects.Type, Left([Name],1)
HAVING (((MSysObjects.Type)=5) AND ((Left([Name],1))<>"~"));
 
Sorry about that - here's the modified query for the names:
Code:
SELECT MSysObjects.Name
FROM MSysObjects
WHERE (((MSysObjects.Type)=5) AND ((Left([Name],1))<>"~"));
 
Hmm...I wasn't aware you could run queries on system objects. Learn something new every day.
 
Hmm...I wasn't aware you could run queries on system objects. Learn something new every day.

Yeah, I didn't know that one until about 2 years ago and it has come in handy many times since. :)
 
Yup. System tables are just tables.

But you don't own them even if you own the database. They are always locked for writing from queries and such.

I once wrote a cross-referencer that queried the SYS tables. Still have the code somewhere. The real bear was parsing the VBA to find references from that sucker.
 

Users who are viewing this thread

Back
Top Bottom