Thursday, November 19, 2009

Access System Tables

While working on a project with hundreds of reports, each with a query, I wanted a list of each report along with its query. I found out two things. Hidden tables such as MSysObjects and programatically accessing Object dependencies.
I will talk about the hidden tables first.
1. Under 2007, go to the Office button in the upper-left corner of Access.
2. Select Access Options.
3. Select Current Database.
4. Under Navigation, select Navigation Options.
5. Check Show System Objects.

Now when creating a query, you have simple access to tables such as MSysOjects where you can list objects like reports or queries.

To list all the report names, I used
SELECT Name FROM MSysObjects WHERE Not Like "~*" And Not Like "MSys*" AND Type = "-32764"
This lists only reports and excludes system reports.

Under MSysQueries, you can list query expressions.
SELECT MsysObjects.Name, MSysQueries.Expression
FROM MSysQueries INNER JOIN MsysObjects ON MSysQueries.ObjectId = MsysObjects.Id
WHERE (((MsysObjects.Name) Not Like "~*" And (MsysObjects.Name) Not Like "MSys*") AND ((MSysQueries.Attribute)=8) AND ((MsysObjects.Type)=5));
This lists the queries and the criteria. You can list much more.
These system tables do not list what report uses what query. That is where dependencies come in.

No comments: