Audit Trail

kedarj

Registered User.
Local time
Today, 02:30
Joined
Sep 7, 2005
Messages
58
Hi,
I am trying to use Audit Trail in Access2000. I tried to look at this snippet from Microsoft. But I am getting an error when I save the record. Actually I have a form with 8 tab pages. It tracks that the change is made, even though it gives error message, but does not track which field was changed. I would appreciate if someone can help me.
Regards
K

Function AuditTrail()
On Error GoTo Err_Handler

Dim MyForm As Form, C As Control, xName As String
Set MyForm = Screen.ActiveForm

'Set date and current user if form has been updated.
MyForm!Updates = MyForm!Updates & Chr(13) & Chr(10) & _
"Changes made on " & Date & " by " & CurrentUser() & ";"

'If new record, record it in audit trail and exit sub.
If MyForm.NewRecord = True Then
MyForm!Updates = MyForm!Updates & Chr(13) & Chr(10) & _
"New Record """
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 Updates field.
If C.Name <> "Updates" Then

' If control was previously Null, record "previous
' value was blank."
If IsNull(C.OldValue) Or C.OldValue = "" Then
MyForm!Updates = MyForm!Updates & Chr(13) & _
Chr(10) & C.Name & "--previous value was blank"

' If control had previous value, record previous value.
ElseIf C.Value <> C.OldValue Then
MyForm!Updates = MyForm!Updates & Chr(13) & Chr(10) & _
C.Name & "==previous value was " & C.OldValue
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
 
It looks like it would record the Control name along with the value. What error are you getting? Errors can clear out variables when they happen.
 
@RuralGuy

May I ask why you went crazy at me at MSN? Said things that are hurtful and mean are not truthful and the event that occured did not needed it? If you did not want to help me anymore live, then please say so. I even wanted to pay you for your help as a sign of appreciation. You are a mean person RuralGuy for what you have done to me, and to be honest I did not deserve it.
 
I get an error on 3251-Operation not supported. But still it stores the changes made to the form. Quite wierd, but for some fields it says : for e.g. Changed name To Tim from Name Tom.
But for some fields there is no such message. What could be the problem?
 
Why not try adding an Else to your If ElseIf End If construct and see what else might be happening.
 
I changed the code and have now implemented the one from gHudson. It is also giving the same error. Moreover, it updates the audit trai lfield for certain fields only. what could be the reason?
 

Users who are viewing this thread

Back
Top Bottom