View Full Version : Automatically update date/time field


vexing
04-16-2001, 03:48 PM
I am having trouble with a time field in a form. The problem is:

The time field is set to default of '=time$()' so the time field is filled in automatically with the current time. Problem is, I need the time field to only fill itself in AFTER the record is entered, not at the beginning. Reason for this is that when a record is opened, it may sit there for hours before any info is actually entered into it. If the time is filled in when the record is opened, by the time the record is finished, it would be way off... I have tried to creat an event procedure to assign the '=time$()' command to happen 'After Update' but can't get it to work. Can anyone give my some help, advice, or code samples?

R. Hicks
04-16-2001, 04:35 PM
Try using the "Before Insert" event of the form to do what you need:

Private Sub Form_BeforeInsert(Cancel As Integer)
Me![YourTimeEntry] = Time$()
End Sub

"YourTimeEntry" needs to be the name of the control that you using to record the Time value.

HTH
RDH

vexing
04-16-2001, 04:50 PM
Thanx for your help,
I think I got it working. This is what I'm using:

Private Sub Form_BeforeUpdate(Cancel As Integer)
Me.Date = (Now)
Me.Time = (Now)
End Sub

Rich
04-16-2001, 10:20 PM
You don't need two separate fields to store date and time one field will record both.