Hi
I am trying to create an audit trail of changes to control values on forms within a database.
I have found a method on the internet, which has a module to insert the relevant information into a table called Audit.
The problem I have found with the code is that if the control is 'blank' or 'Null' then the record change was ignored.
I have modified the code slightly to check if the .OldValue was null to use " " as a filler
However when I try this for the .Value portion of the code, I still get no record.
Basically if the user clear the field with the backspace key or the delete key the code believes there is no change in the field values.
Can someone give me a pointer as to how to sort this.
Code is below
Sub AuditTrail(frm As Form, recordid As Control)
Dim ctl As Control
Dim varBefore As Variant
Dim varAfter As Variant
Dim strControlName As String
Dim strSQL As String
On Error GoTo ErrHandler
'Get changed values.
For Each ctl In frm.Controls
With ctl
'Avoid labels and other controls with Value property.
Select Case ctl.ControlType
Case acTextBox
If .Value <> .OldValue Then
If Not IsNull(.OldValue) Then
varBefore = .OldValue
Else
varBefore = " "
End If
If Nz(IsNull(.Value), 0) = 0 Then
varAfter = " "
Else
varAfter = .Value
End If
Many thanks
Richard
I am trying to create an audit trail of changes to control values on forms within a database.
I have found a method on the internet, which has a module to insert the relevant information into a table called Audit.
The problem I have found with the code is that if the control is 'blank' or 'Null' then the record change was ignored.
I have modified the code slightly to check if the .OldValue was null to use " " as a filler
However when I try this for the .Value portion of the code, I still get no record.
Basically if the user clear the field with the backspace key or the delete key the code believes there is no change in the field values.
Can someone give me a pointer as to how to sort this.
Code is below
Sub AuditTrail(frm As Form, recordid As Control)
Dim ctl As Control
Dim varBefore As Variant
Dim varAfter As Variant
Dim strControlName As String
Dim strSQL As String
On Error GoTo ErrHandler
'Get changed values.
For Each ctl In frm.Controls
With ctl
'Avoid labels and other controls with Value property.
Select Case ctl.ControlType
Case acTextBox
If .Value <> .OldValue Then
If Not IsNull(.OldValue) Then
varBefore = .OldValue
Else
varBefore = " "
End If
If Nz(IsNull(.Value), 0) = 0 Then
varAfter = " "
Else
varAfter = .Value
End If
Many thanks
Richard