Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Date Created and Date Modified Fields 1

Status
Not open for further replies.

czarjosh

Technical User
Jul 14, 2002
79
US
How do I create a field in teh table that will automatically insert the time the record was made, and how do I create a field that automtaically updates when the record was modified?

Josh
 
Field name = DateCreated DateTime
Default Value = Now()
That's all for that one. It will work whether data is entered through a form or directly into the table.


Last modified will only work if data is entered via a form.

On the table you need:
Field name = DateModified DateTime

In the Form BeforeUpdate event procedure :
me.DateModified = Now()
 
In table design view for the table, define a field (DateCreated for example) with type Date and set its default value to "= Now()". That will place a the current datetime on each new record at the time it is created.

For the update of a record, you will need to explicitly set a "DateUpdated" field's value every time you do an update.

In SQL that would be
[blue][tt]
UPDATE tbl SET DateUpdated = Now(), ...
[/tt][/blue]
In Code
[blue][tt]
Dim rs As Recordset
' Open the recordset
rs![DateUpdated] = Now()
... Other Code ...
[/tt][/blue]
If you are updating via bound controls then you will need to trap the "BeforeUpdate" event and set the value there.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top