Tracking Complete Edit History

This code will track the complete edit history of a document. For any field
value change, the date, user, fieldname, previous value, and new value will be
stored in the EditHistory field.
Step 1:
Create a Field on your form called EditHistory. Set it to a multi-value text
field, computed (formula = EditHistory), separate multiple values when user
enters ?;?, display separate values with New Line.

Step 2:
Declare a dynamic array in the Form (Declarations) section-

Form (Declarations)
Dim FieldValues() As String

Step 3:
Add the following code to PostModeChange. The code is placed in PostModeChange
because there is no reason to build the array of field values if the document
is not being edited. *If documents open in edit mode, place this code in
PostOpen instead of PostModeChange.

The field values are taken from the Form, not the uidocument in order to avoid
tracking hidden notes fields, such as $UpdatedBy.

Sub Postmodechange(Source As Notesuidocument)
'build array of current values
Dim session As New NotesSession
Dim db As NotesDatabase
Dim doc As NotesDocument
Dim form As NotesForm
Dim fieldnum As Integer
Dim counter As Integer

Set db = session.CurrentDatabase
Set doc = Source.Document
Set form = db.GetForm(doc.Form(0))
fieldnum = Ubound(form.fields)

Redim FieldValues(fieldnum,1)

counter = 0
Forall field In form.fields
FieldValues(counter,0) = field
FieldValues(counter,1) = source.fieldgettext(field)
counter = counter + 1
End Forall
End Sub

Step 4:
Add the following code to the end of QuerySave (after all edit checking is

Sub Querysave(Source As Notesuidocument, Continue As Variant)
If Not Source.IsNewDoc Then
Call EditHistory
End If
End Sub

Step 5:
Create the EditHistory sub -You can copy this code into the Form (Declarations)
section. This code adds a line to the EditHistory field for each modified
field value. The line consists of the date, user name, fieldname, prior value,
and new value (tab separated).

Sub EditHistory
Dim session As New NotesSession
Dim workspace As New NotesUIWorkspace
Dim source As NotesUIDocument
Dim fieldnum As Integer
Dim entry As String

Set source = workspace.CurrentDocument

For fieldnum = 0 To Ubound(FieldValues)
If FieldValues(fieldnum,1) <>source.fieldgettext(FieldValues(fieldnum,0)) Then
entry = Date$+Chr(9)+session.CommonUserName+Chr(9) +

Call source.FieldAppendText("EditHistory",";"+entry)
End If

End Sub

This was first published in November 2000

There are Comments. Add yours.

TIP: Want to include a code block in your comment? Use <pre> or <code> tags around the desired text. Ex: <code>insert code</code>

REGISTER or login:

Forgot Password?
By submitting you agree to receive email from TechTarget and its partners. If you reside outside of the United States, you consent to having your personal data transferred to and processed in the United States. Privacy
Sort by: OldestNewest

Forgot Password?

No problem! Submit your e-mail address below. We'll send you an email containing your password.

Your password has been sent to:

Disclaimer: Our Tips Exchange is a forum for you to share technical advice and expertise with your peers and to learn from other enterprise IT professionals. TechTarget provides the infrastructure to facilitate this sharing of information. However, we cannot guarantee the accuracy or validity of the material submitted. You agree that your use of the Ask The Expert services and your reliance on any questions, answers, information or other materials received through this Web site is at your own risk.