Share via

How do I make a comments history on Microsoft access

Anonymous
2024-12-16T12:42:25+00:00

Hi guys

I am trying to replicate the comments history feature from the Microsoft Access template named "Asset Tracking".

There is a form named "Asset Details" . On this form there is a Tab control, with a comments page. On this Comments page there are two text boxes. One for New comments and one for Comments history. I am trying to replicate these New Comments and Comment history on my own database. However am struggling. I am familiar with the code used for the comment history text box :

=ColumnHistory([RecordSource],"Comments","[ID]=" & Nz([txtID],0))

However when doing this I have the text box come up with "#Name?" I have followed many instructions on what might be causing the incident and yet can't seem to get it to work. Help would be much appreciated.

Kind regards

Harry

Microsoft 365 and Office | Access | For business | Windows

Locked Question. This question was migrated from the Microsoft Support Community. You can vote on whether it's helpful, but you can't add comments or replies or follow the question.

0 comments No comments

5 answers

Sort by: Most helpful
  1. Anonymous
    2024-12-16T13:32:39+00:00

    Here is the reference for the ColumnHistory method:

    Application.ColumnHistory method (Access) | Microsoft Learn

    Here is a link to related question with more information about the AppendOnly property for Long Text (memo) fields:

    Access Memo Field Append Only - Microsoft Comunity

    I hope this helps you with your solution.

    1 person found this answer helpful.
    0 comments No comments
  2. ScottGem 68,810 Reputation points Volunteer Moderator
    2024-12-16T16:16:16+00:00

    Access templates are designed as examples of how to do things in Access. Sometimes the templates use features that most developers eschew. This appears to be one such case. As Ken has said, using a memo field to store multiple comments is inefficient. Maintaining a log of comments can be done much simpler.

    tblAssetcomments

    AssetcommentID (PK autonumber)

    AssetID (FK)

    CommentDate

    Comment

    Then simply add a subform to your main Asset form linked on AssetID and you can add new comments and see a history of comments.

    0 comments No comments
  3. Anonymous
    2024-12-16T14:17:09+00:00

    According to the documentation the first argument of the ColumnHistory method should be a table name.  Referencing the form's RecordSource property therefore, would require the RecordSource property to be a table name.  Is that the case with your form?  I don't see any cogent reason for doing this rather than using the table name as a literal string.  Substitute the table name, delimited by quotes, and set the long text (memo) field's AppendOnly property to True, and you should have no problem.

    However, rather than using the long text field as a data structure, a better solution, in my opinion, would be to decompose the table so that the Comment field is in a separate related table along with a foreign key referencing the primary key of the current table, and a DateTimeStamp column. The primary key of the related table would be a composite of the foreign key and DateTimeStamp columns.  Each comment would be a separate record in that table.  For data input a subform containing only the Comment text box control, in continuous forms view, would be used, based on a query on the related table which returns rows in DateTimeStamp DESC order, i.e. the latest comment would be the first record in the subform.  Adding a new comment would simply be a question of inserting a new record into the subform.  In the subform's BeforeInsert event procedure the foreign key value would be inserted, and the DateTimeStamp column would be assigned a value with:

        Me.ID = Me.Parent.ID

        Me.DateTimeStamp = Now()

    In the subform's AfterInsert event procedure the subform would be requeried with:

        Me.Requery

    which would move the new record to the top of the subform.

    I would, however, not use the generic column name ID as the primary and foreign key column names. Instead use a name which specifically identifies the entity type in question, e.g. TransactionID or similar.

    0 comments No comments
  4. George Hepworth 22,765 Reputation points Volunteer Moderator
    2024-12-16T13:45:03+00:00

    Thank you. I had forgotten that method is now available.

    https://learn.microsoft.com/en-us/office/vba/api/access.application.columnhistory

    0 comments No comments
  5. George Hepworth 22,765 Reputation points Volunteer Moderator
    2024-12-16T13:16:54+00:00

    Please verify that this is the exact code in the control source in the original form and that it works as intended in that form.

    =ColumnHistory([RecordSource],"Comments","[ID]=" & Nz([txtID],0))

    That looks like a hybrid of an attempt at a function and a DLookup and, as such, should not work as is. But we don't know what it should be, unless it is intended to be a DLookup:

    =DLookup("SomeFieldInTheCommentsTable", "Comments", "[ID] = " & Nz([txtID],0)

    Thanks for clarifying the context.

    0 comments No comments