How does one add a comment to an MS Access Query, to provide a description of what it does?
Once added, how can one retrieve such comments programmatically?
How does one add a comment to an MS Access Query, to provide a description of what it does?
Once added, how can one retrieve such comments programmatically?
It is not possible to add comments to 'normal' Access queries, that is, a QueryDef in an mdb, which is why a number of people recommend storing the sql for queries in a table.
I decided to add a condition to the
Where
Clause that always evaluates true but allows the coder to find your comment.The last line always evaluates to true so it doesn't affect the data returned but allows you to leave a comment for the next guy.
You can add a comment to an MSAccess query as follows: Create a dummy field in the query. Not elegant but is self-documentating and contained in the query, which makes cheking it into source code control alot more feasible! Jere's an example. Go into SQL view and add the dummy field (you can do from design view too):
Run the query:
Note the use of ";" as field delimiter in qryHISTORY field, and ";;" as an end of comment, and use of ISO date format and intials, as well as comment. Have tested this with up to 646 characters in the qryHISTORY field.
if you are trying to add a general note to the overall object (query or table etc..)
Access 2016 go to navigation pane, highlight object, right click, select object / table properties, add a note in the description window i.e. inventory "table last last updated 05/31/17"
NOTE: Confirmed with Access 2003, don't know about earlier versions.
For a query in an MDB you can right-click in the query designer (anywhere in the empty space where the tables are), select Properties from the context menu, and enter text in the Description property.
You're limited to 256 characters, but it's better than nothing.
You can get at the description programatically with something like this:
In the query design:
Note:
If you don't sort, the field will be removed by access. So, make sure you've unchecked show and sorted the column.