To do this I wrote a fairly simple sub which loops through the controls collection for the form & tests to see if the value has changed. If the value has changed a new entry is made in my history table, logging who, when & what was changed.
Sub HistoryLog(FormName As String, RefNo As String)
On Error GoTo History_Err
Dim ctl As Control, frm As Form, strNewValue As String, strOldValue As String
Set frm = Forms(FormName)
Set cnn = CurrentProject.Connection
Set rst = New ADODB.Recordset
'Open the appropriate recordset
rst.Open ("SELECT * FROM HistoryTable"), cnn, adOpenStatic, adLockPessimistic
'Loop through all controls
For Each ctl In frm.Controls
'Only examine TextBoxes or ComboBoxes
If ctl.ControlType = acTextBox Or ctl.ControlType = acComboBox Or ctl.ControlType = acCheckBox Then
'Only examine visible, unlocked controls
If ctl.Locked = False And ctl.Visible = True Then
'Dont allow nulls to propogate
strNewValue = Nz(ctl.Value, "Empty")
strOldValue = Nz(ctl.OldValue, "Empty")
'Dont allow Zero-Length-Strings to propogate
If strNewValue = "" Then strNewValue = "Empty"
If strOldValue = "" Then strNewValue = "Empty"
'If value in control has changed create a history record
If strOldValue <> strNewValue Then
rst.AddNew
rst.Fields("RefNo") = RefNo
rst.Fields("ModField") = ctl.Name
rst.Fields("OldValue") = strOldValue
rst.Fields("NewValue") = strNewValue
rst.Update
Else
'Do nothing
End If
Else
'Do Nothing
End If
End If
Next ctl
History_Exit:
Exit Sub
History_Err:
MsgBox Error$
Resume History_Exit
End Sub
Then I just use the BeforeUpdate event of the data-entry forms to kick off the procedure.
N.B. My underling history table automatically inserts the username (Using Environ("UserName")) & InsertionDate (Using Now()) for the column default values.
--
Cheers,
James Goodman MCSE, MCDBA
http://www.angelfire.com/sports/f1pictures