Hi,
Following code is working perfectly when form is used as main but when inserted as sub form it works only for main form field & doesn't record anything for sub form fields. What necessary changes i might need to do in this.
Following code is working perfectly when form is used as main but when inserted as sub form it works only for main form field & doesn't record anything for sub form fields. What necessary changes i might need to do in this.
Code:
Sub AuditChanges(IDField As String) On Error GoTo AuditChanges_Err Dim cnn As ADODB.Connection Dim rst As ADODB.Recordset Dim ctl As Control Dim datTimeCheck As Date Dim strUserID As String Set cnn = CurrentProject.Connection Set rst = New ADODB.Recordset rst.Open "SELECT * FROM tblAuditTrail", cnn, adOpenDynamic, adLockOptimistic datTimeCheck = Now() strUserID = Environ("USERNAME") For Each ctl In Screen.ActiveForm.Controls If ctl.Tag = "Audit" Then If Nz(ctl.Value) <> Nz(ctl.OldValue) Then With rst .AddNew ![DateTime] = datTimeCheck ![UserName] = strUserID ![FormName] = Screen.ActiveForm.Name ![RecordID] = Screen.ActiveForm.Controls(IDField).Value ![FieldName] = ctl.ControlSource ![OldValue] = ctl.OldValue ![NewValue] = ctl.Value .Update End With End If End If Next ctl AuditChanges_Exit: On Error Resume Next rst.Close cnn.Close Set rst = Nothing Set cnn = Nothing Exit Sub AuditChanges_Err: MsgBox Err.Description, vbCritical, "ERROR!" Resume AuditChanges_Exit End Sub
Comment