sqlms-accesscode-formatting

How do I force MS Access to retain its SQL formatting?


I have a lot of SQL at work in MS-Access, and I need to formatted so that it's human readable. The issue is when I change between views I end up with the SQL being condensed down into something that I can't read.

How do I force SQL to retain its 'shape' when I go to other views?


Solution

  • I found a hack, here. The secret lies in enclosing your query inside a dummy query. Like so:

    SELECT * FROM (SELECT   <-----here
    Table1.Field1,
    Table1.Field2
    FROM
    Table1
    
    WHERE
    Table1.Field2 = "Yes") AS query1 <-----here
    

    I've indicated where and how you wrap the code. The only issue I can see is if you wanted to edit the code in design view, then it doesn't seem to pick the enclosed code up at all.