S
SandySun
Hi I found this code from utter angel for creating audit trails, and it does
not respond well to one to many tables within a query (error 3251, Operation
is not supported for this type of object).
I am trying to create an audit trail for all of my forms ....however I would
like to have only one table to store all of the changes.....any suggestions?
Thanks kindly.
Option Explicit
Option Compare Text
Public Sub WriteToAuditLog(ByRef frmThisForm As Form)
Dim ctlC As Control
On Error GoTo ErrorHandler
With CurrentDb.OpenRecordset("tblAudit")
' If not passed a message, check the controls.
For Each ctlC In frmThisForm
Select Case ctlC.ControlType
Case acTextBox, acCheckBox, acComboBox
If Nz(ctlC.Value, "") <> Nz(ctlC.OldValue, "") Then
.AddNew
.Fields("FormName") = frmThisForm.NAME
.Fields("FieldChanged") = ctlC.NAME
.Fields("FieldChangedFrom") = ctlC.OldValue
.Fields("FieldChangedTo") = ctlC.Value
.Fields("User") = GetUserName()
.Update
End If
End Select
Next ctlC
Else
' Add the message.
.AddNew
.Fields("FormName") = frmThisForm.NAME
.Fields("User") = GetUserName()
.Update
End If
.Close
End With
ExitProcedure:
Exit Sub
ErrorHandler:
DisplayError "WriteToAuditLog", conModuleName
Resume ExitProcedure
End Sub
not respond well to one to many tables within a query (error 3251, Operation
is not supported for this type of object).
I am trying to create an audit trail for all of my forms ....however I would
like to have only one table to store all of the changes.....any suggestions?
Thanks kindly.
Option Explicit
Option Compare Text
Public Sub WriteToAuditLog(ByRef frmThisForm As Form)
Dim ctlC As Control
On Error GoTo ErrorHandler
With CurrentDb.OpenRecordset("tblAudit")
' If not passed a message, check the controls.
For Each ctlC In frmThisForm
Select Case ctlC.ControlType
Case acTextBox, acCheckBox, acComboBox
If Nz(ctlC.Value, "") <> Nz(ctlC.OldValue, "") Then
.AddNew
.Fields("FormName") = frmThisForm.NAME
.Fields("FieldChanged") = ctlC.NAME
.Fields("FieldChangedFrom") = ctlC.OldValue
.Fields("FieldChangedTo") = ctlC.Value
.Fields("User") = GetUserName()
.Update
End If
End Select
Next ctlC
Else
' Add the message.
.AddNew
.Fields("FormName") = frmThisForm.NAME
.Fields("User") = GetUserName()
.Update
End If
.Close
End With
ExitProcedure:
Exit Sub
ErrorHandler:
DisplayError "WriteToAuditLog", conModuleName
Resume ExitProcedure
End Sub