Microsoft KB Archive/197592

= How to create an audit trail of record changes in a form in Access 2000 =

Article ID: 197592

Article Last Modified on 10/11/2006

-

APPLIES TO


 * Microsoft Access 2000 Standard Edition

-



This article was previously published under Q197592





For a Microsoft Access 97 version of this article, see 183792.



Moderate: Requires basic macro, coding, and interoperability skills.



SUMMARY
This article shows you how to create a procedure in Microsoft Visual Basic for Applications that will keep an audit trail of the changes that are made to a record in a form.



MORE INFORMATION
Microsoft provides programming examples for illustration only, without warranty either expressed or implied. This includes, but is not limited to, the implied warranties of merchantability or fitness for a particular purpose. This article assumes that you are familiar with the programming language that is being demonstrated and with the tools that are used to create and to debug procedures. Microsoft support engineers can help explain the functionality of a particular procedure, but they will not modify these examples to provide added functionality or construct procedures to meet your specific requirements. To create an audit trail of changes to a form, follow these steps:  Open the sample database Northwind.mdb.  Create a module and type the following line in the Declarations section if it is not already there: Option Explicit   Type the following procedure: Function AuditTrail On Error GoTo Err_Handler Dim MyForm As Form, C As Control, xName As String Set MyForm = Screen.ActiveForm

'Set date and current user if form has been updated. MyForm!Updates = MyForm!Updates & Chr(13) & Chr(10) & _ "Changes made on " & Date & " by " & CurrentUser & ";"

'If new record, record it in audit trail and exit sub. If MyForm.NewRecord = True Then MyForm!Updates = MyForm!Updates & Chr(13) & Chr(10) & _ "New Record """ End If

'Check each data entry control for change and record 'old value of Control. For Each C In MyForm.Controls 'Only check data entry type controls. Select Case C.ControlType Case acTextBox, acComboBox, acListBox, acOptionGroup ' Skip Updates field. If C.Name <> "Updates" Then ' If control was previously Null, record "previous           ' value was blank." If IsNull(C.OldValue) Or C.OldValue = "" Then MyForm!Updates = MyForm!Updates & Chr(13) & _ Chr(10) & C.Name & "--previous value was blank" ' If control had previous value, record previous value. ElseIf IIF(IsNull(C.Value),"",C.Value) <> C.OldValue Then MyForm!Updates = MyForm!Updates & Chr(13) & Chr(10) & _ C.Name & "==previous value was " & C.OldValue End If           End If        End Select Next C

TryNextC: Exit Function Err_Handler: If Err.Number <> 64535 Then MsgBox "Error #: " & Err.Number & vbCrLf & "Description: " & Err.Description End If   Resume TryNextC End Function  Save the Module as Module1 and close the Visual Basic Editor. Open the Customers table in Design view and add a new field called Updates. Set the data type of the field to Memo. Close and save the table.</li> Open the Customers form in Design view.</li> In the BeforeUpdate event of the form, type =AuditTrail .</li> If the field list is not displayed, click Field List on the View menu and drag the Updates field from the field list to the form.</li> Open the form in Form view, make a change to the Company Name field of the current record, and press SHIFT+ENTER to save the record.</li></ol>

Note that the Updates field has an entry showing the change that you made to the Company Name field. You can also hide the Updates field if you do not want to see it on the form.

Additional query words: Tracking Information date time stamp

Keywords: kbhowto kbprogramming KB197592

-

[mailto:TECHNET@MICROSOFT.COM Send feedback to Microsoft]

© Microsoft Corporation. All rights reserved.