Search code examples
ms-accessms-access-2010legacylegacy-codelegacy-database

Un-nesting nested MS Access sql queries


I've been given a small Access database to work on. The guy who created it wrote many custom queries to generate reports. I've been tasked with modifying the reports and the guy who initially wrote the queries is gone and left no documentation.

My biggest issue is that he nested the queries 5+ levels deep and it's incredibly difficult for me to read the way it is. The queries he wrote generally have this format but are way more complex.

SELECT thisCol, thatCol, theOtherCol
FROM CustomQuery1, CustomQuery2, CustomQuery3 

And CustomQuery{1,2,3} are each written the exact same way where they reference multiple other sub-queries. Not only do I find this incredibly hard to read but I worry if I modify one of the queries that perhaps it's called elsewhere in another query that I'm not aware of that will break another report. I'm wondering if there's a way to analyze all the queries to figure out which ones are called by what other queries and/or if there's some tool out there that could automatically un-nest them or if I just have to trace through them all manually.


Solution

  • One thing that will help you a good deal is the Object Dependencies pane, which is built into Access. Note that you'll need to turn on Name AutoCorrect while checking that, even if you have it off the rest of the time, as is usually best. Also, it won't display VBA code references to queries, so you'll have to check those yourself by searching.