oldvalue test for timestamp field

  • Thread starter Thread starter Rick
  • Start date Start date
R

Rick

I need help with oldvalue...
Ok - I have a field to indicate when a record has been
modified. I want to indicate at the end of the field what
type of change was made to the record. This code works
ONCE. But, let's say I enter a date of 12/15/03 in a
record, the timestamp is updated and indicates a date
change. If I go to another record and enter a different
date, it works. If I go to another record and enter
12/15/03, it does not indicate a date change. Any
suggestions? My understanding of 'oldvalue' is that it
stores the old value when you move the focus to a new
record.

Here is my code...

--------------------------------------------

Private Sub Form_BeforeUpdate(Cancel As Integer)
If Me.Dirty Then

Dim Datechg
Datechg = ""
If InstallDate.Value <> InstallDate.OldValue Or
DateCompleted.Value <> DateCompleted.OldValue Then Datechg
= "D"

Dim Succchg
Succchg = ""
If SuccessFactor.Value <> SuccessFactor.OldValue Then
Succchg = "S"


Dim Milechg
Milechg = ""
If Travel_Requested.Value <> Travel_Requested.OldValue Or
Readiness.Value <> Readiness.OldValue _
Or Prelaunch.Value <> Prelaunch.OldValue Or
Checklist.Value <> Checklist.OldValue Or _
Signoff.Value <> Signoff.OldValue Or ATB.Value <>
ATB.OldValue Or Followup.Value <> Followup.OldValue _
Then Milechg = "M"

Dim UserChg
UserChg = ""
If UserID.Value <> UserID.OldValue Then UserChg = "U"
If SupervisorIfBorrowed.Value <>
SupervisorIfBorrowed.OldValue Then UserChg = "U"

Me.Timestamp = Format(CurrentUser, ">") & " " & date & " "
& Time & Datechg & Succchg & Milechg & UserChg

End If
End Sub
 
When I say "It doesn't work" what I mean is that the
timestamp field is updated, but the 'D' does not appear to
indicate that a change was made to the value in a date
field.

Rick
 
Rick said:
When I say "It doesn't work" what I mean is that the
timestamp field is updated, but the 'D' does not appear to
indicate that a change was made to the value in a date
field.

Rick

Incorrect. OldValue is the previous value of a bound control that has been
changed in the current record. It is useful until the record has been
saved at which point it will always be the same as the Value property. It
means nothing in the context of moving between records.
 
I'm not sure that answers my question, or tells me how to
make this timestamp work acurately...

When I move to the next record, my record *is* saved. So
let's say I have a record with somefield=1. If I change
it to 2 and page down, then I will move to the next
record. If somefield=9 on this next record, what is
my'oldvalue'? Is it still '1' or does it become '9' when
I move to a new record?

If it becomes '9', then I still don't understand why my
code is not working. If it remains '1' then I do
understand why it is not working. It would be comparing
the 'oldvalue' from the first record I touched to the
current value for a totally different record.

That does not seem like the way it should work.
 
Rick said:
I'm not sure that answers my question, or tells me how to
make this timestamp work acurately...

When I move to the next record, my record *is* saved. So
let's say I have a record with somefield=1. If I change
it to 2 and page down, then I will move to the next
record. If somefield=9 on this next record, what is
my'oldvalue'? Is it still '1' or does it become '9' when
I move to a new record?

It becomes 9.

OldValue is the same as Value for all controls when the record is not
dirty. This would be the case whenever you initially navigate to a record.

When the record is dirty, then OldValue is the same as Value for all
controls that have not been changed since the record was dirtied. For
controls that have been changed since the record was dirtied, the OldValue
reflects the value of the control before the record was dirtied whereas
Value reflects what is in the control currently.

If you are in the process of changing a control, but haven't finished yet,
then OldValue and Value will be the same and what you have entered so far
will be in the Text property.
 
You seem to be building an audit Log. Try Rolling your own
In Form.OnCurrent
mvarSomeField = me.txtSomeField

In Form.AfterUpDate
if mvarSomeField <> me.txtSomeField
LogChanges mvarSomeField, me.txtSomeField

in
Sub LogChanges (varOldValue, varNewValue)
.......
with rstAudit
.Addnew
!TimeStamp = Now()
!NewValue = varNewValue
!OldValue = varOldValue
.Update
end with
.....
End Sub

Regards Greg Kraushaar
Wentworth Falls Australia
(Do not email - the reply address is a Spam spoofer)
(If you really must, remove all UCase and numbers)
 
Back
Top