DateCreated and DateModified

  • Thread starter Thread starter Tom
  • Start date Start date
T

Tom

I have two fields in my record, DateCreated and DateModified. All I
want to do is grab the value of the current date and time if the
record is created and/or modified, as appropriate. I've tried and
tried, but nothing I try works. Default value, On Got Focus, Before
Update, etc.

Any thoughts/suggestions/code would be appreciated.

Thanks in advance,

Tom
 
For DateCreated, all you need to do is open your table in design view, and
set the fields DefaultValue (lower pane) to:
=Now()

For DateModified, you can only achieve this if updates are made through a
form. Use the form's BeforeUpdate event procedure to assign the date/time:
Private Sub Form_BeforeUpdate(Cancel As Integer)
Me.DateModified = Now()
End Sub
 
Great. I THOUGHT it had to be relatively simple. (He says...)

The solution for DateCreated works just fine. I'm having trouble with
the DateModified. On a new record, I get the same date and time as
for DateCreated. Whether or not I try to update an existing record,
or add another, then modify it, the date & time, if present, does NOT
change.

I believe I did what you said, correctly. Perhaps it's my form. I
used the form wizard. I don't have any "update" button. (Sorry, I've
done next to nothing with forms...so far.)

What do you think?

Thanks,

Tom
 
Did you use the BeforeUpdate event of the *form*, or that of a control?

1. Open the form in design view.
2. Open the Properties box (View menu).
3. Make sure the Properties box says "Form" in its title.
4. On the Event tab, click BeforeUpdate.
5. Set the property to: [Event Procedure]
6. Click the Build button (...) beside this. Access opens the code window.
7. Paste in the line between the "Private Sub" and "End Sub".
8. Check that it compiles: Compile on Debug menu.
9. Save.
 
You said "form". But did *I* listen? NO. *I* did "DateModified".

I followed your latest instructions, and it works. Peachy keen fine,
as the saying goes. Just what I wanted.

Thanks so much!

I'll go crawl off to my corner now..... :)

Tom
 
Back
Top