How do you comment an MS-access Query?

前端 未结 9 1861
失恋的感觉
失恋的感觉 2020-12-29 20:04

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?

相关标签:
9条回答
  • 2020-12-29 20:40

    I decided to add a condition to the Where Clause that always evaluates true but allows the coder to find your comment.

    Select
       ...
    From
       ...
    Where
       ....
       And "Comment: FYI, Access doesn't support normal comments!"<>""
    

    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.

    0 讨论(0)
  • 2020-12-29 20:40

    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.

    0 讨论(0)
  • 2020-12-29 20:44

    If you have a query with a lot of criteria, it can be tricky to remember what each one does. I add a text field into the original table - call it "comments" or "documentation". Then I include it in the query with a comment for each criteria.

    Comments need to be written like like this so that all relevant rows are returned. Unfortunately, as I'm a new poster, I can't add a screenshot!

    So here goes without

    Field:   | Comment              |ContractStatus     | ProblemDealtWith | ...... |
    
    Table:   | ElecContracts        |ElecContracts      | ElecContracts    | ...... |
    
    Sort:  
    
    Show:  
    
    Criteria | <> "all problems are | "objection" Or |
    
             | picked up with this  | "rejected" Or  |
    
             | criteria" OR Is Null | "rolled"       |
    
             | OR ""
    

    <> tells the query to choose rows that are not equal to the text you entered, otherwise it will only pick up fields that have text equal to your comment i.e. none!

    " " enclose your comment in quotes

    OR Is Null OR "" tells your query to include any rows that have no data in the comments field , otherwise it won't return anything!

    0 讨论(0)
  • 2020-12-29 20:48

    I know this question is very old, but I would like to add a few points, strangely omitted:

    1. you can right-click the query in the container, and click properties, and fill that with your description. The text you input that way is also accessible in design view, in the Descrption property
    2. Each field can be documented as well. Just make sure the properties window is open, then click the query field you want to document, and fill the Description (just above the too little known Format property)

    It's a bit sad that no product (I know of) documents these query fields descriptions and expressions.

    0 讨论(0)
  • 2020-12-29 20:49

    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:

    Dim db As Database
    Dim qry As QueryDef
    
    Set db = Application.CurrentDb
    Set qry = db.QueryDefs("myQuery")
    
    Debug.Print qry.Properties("Description")
    
    0 讨论(0)
  • 2020-12-29 20:49

    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"

    0 讨论(0)
提交回复
热议问题