I can help you with this....
The difficult part is making code work with a subform. However, if you
are only having users input data into a main form
Here is an example of a function that writes change records to a hidden
form bound to a table to track changes to records.
Function AuditTrail()
' Created on 1/18/2005 by Diane Cichelli
' Purpose of function is to record any changes to the active form
' when the form's "Before Update" event property is set to
=AuditTrail()
On Error GoTo Err_Handler
Dim MyForm As Form, C As Control, hideform As Form
Set MyForm = Screen.ActiveForm
'If new record, record it in audit trail and exit sub.
If MyForm.NewRecord = True Then
DoCmd.OpenForm "frm_audit_main_sub", , , , , acHidden
DoCmd.GoToRecord acDataForm, "frm_audit_main_sub", acNewRec
Set hideform = Forms!frm_audit_main_sub
hideform!ChangeDate = Now
hideform!IssueKey = MyForm!Issue
hideform!Type = "New Record"
hideform!DetailKey = 0
DoCmd.Close acForm, "frm_audit_main_sub", acSaveYes
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 non-editable fields .
If C.Name <> "Field" And _
C.Name <> "Previous" And _
C.Name <> "Type" And _
C.Name <> "NewVal" Then
' If control was previously Null or empty, record "previous
' value was blank. Do nothing if new value is also blank or
null
If IsNull(C.Value) Or C.Value = "" Then
If C.OldValue = "" Or IsNull(C.OldValue) Then
Else
MyForm!Field = C.Name
MyForm!Previous = C.OldValue
MyForm!Type = "Delete"
MyForm!NewVal = C.Value
End If
Else
If C.OldValue = "" Or IsNull(C.OldValue) Then
MyForm!Field = C.Name
MyForm!Previous = C.OldValue
MyForm!Type = "Edit"
MyForm!NewVal = C.Value
' This code records the new and old values if there
is a change
ElseIf C.Value <> C.OldValue And C.Value <> "" Then
MyForm!Field = C.Name
MyForm!NewVal = C.Value
MyForm!Previous = C.OldValue
MyForm!Type = "Edit"
End If
End If
If IsNull(MyForm!Field) Or MyForm!Field = "" Then
Else
DoCmd.OpenForm "frm_audit_main_sub", , , , ,
acHidden
DoCmd.GoToRecord acDataForm, "frm_audit_main_sub",
acNewRec
Set hideform = Forms!frm_audit_main_sub
hideform!ChangeDate = Now
hideform!IssueKey = MyForm!Issue
hideform!DetailKey = 0
hideform!Field = MyForm!Field
hideform!Previous = MyForm!Previous
hideform!NewVal = MyForm!NewVal
hideform!Type = MyForm!Type
DoCmd.Close acForm, "frm_audit_main_sub",
acSaveYes
MyForm!Field = ""
MyForm!NewVal = ""
MyForm!Previous = ""
MyForm!Type = ""
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