Default Value: Time()

  • Thread starter Thread starter Brian
  • Start date Start date
B

Brian

We have a simple log database that tracks daily events.
It stays open constantly waiting for new data entry (on
open it uses "gotorecord new"). I set the default value
on the "Time" field for both the form and table to Time()
with the intention of automatically inserting the current
time whenever a new entry was made. This worked well in
Access 97. Anytime new data was entered the time would
update. However after converting to 2000 it doesn't work
exactly the same. Now the time is inserted without any
data being entered into the new record, it is just
automatically there, which is fine except that now the
time is not updated when new data is actually entered.
The focus may remain in the first field of the new record
for minutes or hours before any data is actually entered
which means that users must manually go back and reenter
the time. Also I tried using some of the update
properties with the "set value" command. It worked well
except that occasionally users have to edit entries and I
don't want the time on those records being reset also;
only new records. Is there a different expression I
should be using instead of Time()or someway to use the
newrecord property with an if statement to solve this.
Thanks for your help.
 
Why don't you put an event in the BoforeInsert event of the form to place
the current time in the field?

The Before Insert event will only happen when a new record is being added.
Not when a change is made.

Private Sub Form_BeforeInsert(Cancel As Integer)
SomeField = Time()
End Sub



Rick B



We have a simple log database that tracks daily events.
It stays open constantly waiting for new data entry (on
open it uses "gotorecord new"). I set the default value
on the "Time" field for both the form and table to Time()
with the intention of automatically inserting the current
time whenever a new entry was made. This worked well in
Access 97. Anytime new data was entered the time would
update. However after converting to 2000 it doesn't work
exactly the same. Now the time is inserted without any
data being entered into the new record, it is just
automatically there, which is fine except that now the
time is not updated when new data is actually entered.
The focus may remain in the first field of the new record
for minutes or hours before any data is actually entered
which means that users must manually go back and reenter
the time. Also I tried using some of the update
properties with the "set value" command. It worked well
except that occasionally users have to edit entries and I
don't want the time on those records being reset also;
only new records. Is there a different expression I
should be using instead of Time()or someway to use the
newrecord property with an if statement to solve this.
Thanks for your help.
 
Back
Top