Private Sub Form_BeforeUpdate(Cancel As Integer)
LogAllChanges
End Sub
Private Sub LogAllChanges()
Dim ctl As Control
On Error GoTo Catch
'Loop through all controls on the form
For Each ctl In Me.Controls
'Check if there is a ControlSource set (we are only interested in bound controls)
'An error will occur here for controls without the ControlSource property (labels, etc) - so we
'catch the error and skip to the next control
If ctl.ControlSource <> "" Then
'Check if the control value has changed (handle nulls with nz)
If Nz(ctl.Value, "") <> Nz(ctl.OldValue, "") Then
'Log the change
LogChange ctl.ControlSource, ctl.Value, ctl.OldValue, Me.NewRecord
End If
End If
Skip_Control:
Next
Exit Sub
Catch:
Resume Skip_Control
End Sub
Private Sub LogChange(ByVal FieldName As String, ByVal Value As Variant, ByVal OldValue As Variant, ByVal IsNewRecord As Boolean)
'Your code to write the changes to the log here
End Sub
|