auto date - whenever a record changes

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I want a date field that automatically changes whenever any field in a record
changes.

How do I do this?
 
Access has no triggers, so cannot do this at the engine level.

However, if all changes are made through a form, you can use the
BeforeUpdate event of the form to write the date and time into your field:

Private Sub Form_BeforeUpdate(Cancel As Integer)
Me![NameOfYourDateTimeFieldHere] = Now()
End Sub
 
In the afterupdate event of your form enter:

Me.Yourdatefield = date()

HTH

Rico
 
Rico, better to use Form_BeforeUpdate than Form_AfterUpdate.

There is no point dirtying the record again as soon as it saves, so that it
must save again, which again dirties it so it has to save again, which again
dirties it ...
 
You also might consider using a history table that records all changes
instead of last one. Link history table to your key field. If using logons
you can capture who done it.

Allen Browne said:
Access has no triggers, so cannot do this at the engine level.

However, if all changes are made through a form, you can use the
BeforeUpdate event of the form to write the date and time into your field:

Private Sub Form_BeforeUpdate(Cancel As Integer)
Me![NameOfYourDateTimeFieldHere] = Now()
End Sub

--
Allen Browne - Microsoft MVP. Perth, Western Australia.

Reply to group, rather than allenbrowne at mvps dot org.

I want a date field that automatically changes whenever any field in a
record
changes.

How do I do this?
 
Like this one, Karl:
http://allenbrowne.com/AppAudit.html

--
Allen Browne - Microsoft MVP. Perth, Western Australia.

Reply to group, rather than allenbrowne at mvps dot org.

KARL DEWEY said:
You also might consider using a history table that records all changes
instead of last one. Link history table to your key field. If using
logons
you can capture who done it.

Allen Browne said:
Access has no triggers, so cannot do this at the engine level.

However, if all changes are made through a form, you can use the
BeforeUpdate event of the form to write the date and time into your
field:

Private Sub Form_BeforeUpdate(Cancel As Integer)
Me![NameOfYourDateTimeFieldHere] = Now()
End Sub


"(e-mail address removed)"
<[email protected]>
wrote in message
I want a date field that automatically changes whenever any field in a
record
changes.
 
Allen said:
Access has no triggers, so cannot do this at the engine level.

However, if all changes are made through a form, you can use the
BeforeUpdate event of the form to write the date and time into your field

At the data engine level, you can and should enforce the requirement
for the date to be updated when the data in the row is updated, whether
using forms, Access or otherwise

ALTER TABLE NameOfYourTableHere ADD CONSTRAINT date_must_change CHECK
(NameOfYourDateTimeFieldHere = NOW())
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top