I had the same need recently. Below is what I ended up doing. Basically it
just uses the .ActiveControl and .OldValue properties. It works like it
should, but one drawback is the logging routine needs to be called from the
"On AfterUpdate" event of the field being edited -- not that big of a deal
unless you're constantly adding/dropping fields from a form (if so, you may
be able to find a better place to call it).
Private Sub LogChange()
Dim ctl As Control
Dim strFieldName As String
Dim strOldValue As String
Set ctl = Me.ActiveControl
strFieldName = ctl.ControlSource
strOldValue = Nz(ctl.OldValue, "null")
Call LogDataChange(Me!Import_ID, "PHA", Me!participant_code, strFieldName,
strOldValue)
End Sub
Public Sub LogDataChange(lonImport As Long, strDataType, strKey As String,
strFieldName As String, strOldValue As String)
Dim strSQL As String
strSQL = "INSERT INTO cff_log_Data_Audit (Import_ID, DataType, UniqueKey,
Field_ID, OldValue, User_ID) " & _
"SELECT " & lonImport & ", '" & strDataType & "', '" & strKey & "', '" &
strFieldName & "', '" & strOldValue & "', '" & pubstrUser & "'"
DoCmd.SetWarnings False
DoCmd.RunSQL strSQL
DoCmd.SetWarnings True
End Sub