One to many Audit trails

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top