cklosko
asked on
How do I access a field's old value before it is updated to a new value?
I am creating a change history of updates to fields. I need to capture the old value of the field before it was changed. Within BeforeUpdate, the field already contains the updated value, not the original value. How do I access the field's original value, before the update occurs, in order to be able to capture the old value and the new value, when a field is updated?
Have you tried looking at .OldValue ?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Would I use this in BeforeUPdate?
Private Sub YourControl_BeforeUpdate(C ancel As Integer)
Dim x
x= Nz(Me.YourControl.OldValue ,"")
If x = "" Then ' no old value
' whatever
Else
' has old value - do what ever
End If
End Sub
mx
Dim x
x= Nz(Me.YourControl.OldValue
If x = "" Then ' no old value
' whatever
Else
' has old value - do what ever
End If
End Sub
mx
ASKER
That worked. Thank you.
Yes, you would. See the example I gave in using variables to hold the old value.
The auditing should take place after the record has been saved.
The auditing should take place after the record has been saved.
You need to test OldValue for Null - because there will not be an OldValue for a new record - and you will get a run time error.
mx
mx
mx, Should be okay if sOldValue defined as variant?
Better test that ...
mx
mx
it should be fine so as long as you use a recordset to insert. using sql then its a issue. Probably easier all round just to use NZ without having to phaff about.
Humm ... does not seem to be a problem ... I SWEAR this used to be an issue.
mx
mx
its what I thought, variants handle null. The issue is if you generate sql then it becomes a issue due to the null, but adding via recordsets is fine