recording the last date that data is changed

P

Paul Ponzelli

I would like to store the last date that a change is made to data in any
field in a record. However, I don't want this to occur when a user simply
opens a form and looks at the data; I only want this date to get set to the
current date if the user modifies data in any way.

Will the After Update event serve this purpose, and can I just write
"Me.txtLastModified = Date()"?

Thanks in advance,

Paul
 
R

Rick Brandt

Paul said:
I would like to store the last date that a change is made to data in
any field in a record. However, I don't want this to occur when a
user simply opens a form and looks at the data; I only want this date
to get set to the current date if the user modifies data in any way.

Will the After Update event serve this purpose, and can I just write
"Me.txtLastModified = Date()"?

Thanks in advance,

Paul

Use BeforeUpdate not AfterUpdate. If you update a record in the AfterUpdate
event you create a loop.
 
P

Paul Ponzelli

If I use the Before Update event, I think I need to confirm that the user
doesn't cancel the update.

Can I do that with

If Cancel <> true then
[run my code]
End If

??
 
R

Rick Brandt

Paul said:
If I use the Before Update event, I think I need to confirm that the
user doesn't cancel the update.

Can I do that with

If Cancel <> true then
[run my code]
End If

??

If they cancel the update then any changes made in the BeforeUpdate are also
cancelled.

Unless...are you talking about recording this date in a field of the record
being updated or in a separate table? If in the record being modified then use
BeforeUpdate and you will not have to worry about the user cancelling changes.
If you are storing it in another table then you DO need to use AfterUpdate, but
in that case you would need to run an update query or append query. A simple
Me!FieldName = Date() will only work if "FieldName" is a field in the same
record being changed.
 
P

Paul Ponzelli

Yes, it's a field in the same table with that of the record being changed.

Thanks, Rick.
 
D

Douglas J. Steele

I think you're correct, Rick. I always use the BeforeUpdate event. I wasn't
paying enough attention

However, I do seem to recall that MichKa had some reason for suggesting
using AfterUpdate.
 
Top